Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable hardware acceleration in a SurfaceView?

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.

like image 383
Ericson Willians Avatar asked Mar 07 '14 06:03

Ericson Willians


1 Answers

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

like image 136
shelll Avatar answered Oct 19 '22 23:10

shelll