5

I'm having this "exact" problem:

setShadowLayer Android API differences

I have a player, and enemies, and I'm compiling with 14 API. Problem is: From 14 API on, hardware acceleration is enabled by default, and it is not supported on all drawing methods (For example, the setShadowLayer(), the one that I want to use). So, the solution is simple, just like the one presented in the topic above. Problem is: He uses a View, and I use a SurfaceView for better game performance. My Surface View is declared like this:

public class Screen extends SurfaceView implements Runnable { // Code }

So, I just added to the constructor:

public Screen(Context context) {
    super(context);
    holder = getHolder();
    setLayerType(View.LAYER_TYPE_SOFTWARE, null); // Here.
}

To disable hardware acceleration on my SurfaceView in order to make my shadows not look uggly, and the result: The whole SurfaceView just stops working. I can't show what happens, but It just does not draw anything when I disable hardware acceleration. I'm pretty pessimist about this, because it seems that the SurfaceView itself depends on the hardware acceleration, but the Canvas when drawn into it can't have shadows functioning properly.

Community
  • 1
  • 1
Ericson Willians
  • 7,606
  • 11
  • 63
  • 114
  • 1
    If you're using software rendering, you're giving up a lot of performance, especially on modern devices. At any rate, disabling acceleration on the SurfaceView's Surface might not be possible -- note in http://developer.android.com/guide/topics/graphics/hardware-accel.html it says you can't disable acceleration for a window. Have you tried disabling acceleration for the entire activity or app? – fadden Mar 07 '14 at 15:53
  • Yes, I've tried that part as well. It was useless, the shadows still looked uggly. I decided to give up of the shadow quality, and wait for google to fix that. – Ericson Willians Mar 07 '14 at 21:46
  • My earlier comment was incorrect. As noted in @shelll's answer, the Canvas you get from a SurfaceView's Surface with lockCanvas() is not hardware-accelerated. – fadden Mar 28 '14 at 22:23

1 Answers1

5

According to this the SurfaceView is not HW accelerated at all, so your problem is probably somewhere else.

Community
  • 1
  • 1
shelll
  • 3,234
  • 3
  • 33
  • 67
  • Easy to tell -- just call `Canvas#isHardwareAccelerated()` after locking the Surface. I tried it just now on a `SurfaceView` and confirmed that it was not hardware accelerated. – fadden Mar 28 '14 at 22:22