13

I'm developing on ICS and trying to understand why a Canvas.isHardwareAccelerated() will always return FALSE when using a Canvas inside a SurfaceView.

I've tried a very basic example like this: http://android-coding.blogspot.com/2011/05/drawing-on-surfaceview.html Or this one: http://jmsliu.com/199/android-canvas-example.html

I even modified them to not have any canvas calls inside the draw loop thinking that I might have got in some unsupported HW accel operations for certain drawing calls. I checked this list under "Unsupported Drawing Operations" developer.android.com/guide/topics/graphics/hardware-accel.html but I'm not doing any of that.

I am using the Force GPU rendering flag inside the Developer Options together with inside the manifests, also I'm specifying minSDK/targetSDK >= 14.

The View.isHardwareAccelerated will return TRUE, while the Canvas.isHardwareAccelerated will return always FALSE.

I've seen that Canvas.java has hard-codeded return false for isHardwareAccelerated(), while HardwareCanvas.java has return true. I guess for some reasons I'm not getting the HW path, why?

Can a Canvas inside a SurfaceView be HW accelerated?

Thanks

user1019096
  • 135
  • 1
  • 7

3 Answers3

15

A Canvas returned by SurfaceView.lockCanvas() cannot be hardware accelerated at the moment.

thumbmunkeys
  • 20,606
  • 8
  • 62
  • 110
Romain Guy
  • 97,993
  • 18
  • 219
  • 200
5

it seems that there is a new hide api method unlockHardwareCanvas in android.view.Surface

and here is the example: http://androidxref.com/5.1.0_r1/xref/frameworks/base/tests/HwAccelerationTest/src/com/android/test/hwui/HardwareCanvasSurfaceViewActivity.java

you can use relfecation in production environments.

Juude
  • 1,207
  • 2
  • 13
  • 22
1

Have you stated in your android manifest, that your app wants to use hw acceleration?

This would be something like <application android:hardwareAccelerated="true" ...>

Depending on what you want to do it might also be useful to only activate acceleration only for an activity or window, see http://developer.android.com/guide/topics/graphics/hardware-accel.html for details.

Rudi

nanoquack
  • 949
  • 2
  • 9
  • 26
  • Yes I've stated in my manifest file, as a matter of fact, I can see the View HW accelerated but not the Canvas. – user1019096 Mar 06 '12 at 18:59
  • 1
    @AliAlNoaimi It must have worked on other views but not the SurfaceView. It's simply impossible as stated in another answer. – Pijusn Jul 09 '14 at 15:59