Paul Mennega Paul Mennega - 8 days ago 6
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:

<uses-sdk
android:targetSdkVersion="12"
android:minSdkVersion="12" />

<application
...
android:hardwareAccelerated="true">


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

Any pointers?

EDIT1:

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
onAttachedToWindow()
, right? This is on a Lenovo Tablet running 3.1 BTW.

EDIT2:

I have tried disabling acceleration via setting

<application
...
android:hardwareAccelerated="false">


And I am still seeing true returned from the View in
onAttachedToWindow()
, 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)


EDIT3:

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

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: https://developer.android.com/reference/android/view/Surface.html#lockHardwareCanvas()

Comments