0

When using SurfaceView I am getting around 6 FPS, when I'm drawing pretty much nothing.

I am only drawing a color. So with pretty much NO drawing operations, I'm getting 6 fps, which is extremely horrible.

One thing to note however is that I am using an emulator(genymotion emulator) and have not tried on a real device. However even WITH an emulator when I am drawing nothing I should be getting way more than 6 fps..

So here's my code (import statements not included):

//Activity class which starts the SurfaceView
public class MainActivity extends Activity {

    SView surfaceView;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        surfaceView = new SView(this);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(surfaceView);
    }    
}

//SurfaceView class which draws everything in another thread
class SView extends SurfaceView implements SurfaceHolder.Callback{

    SurfaceHolder holder;
    Canvas mainCanvas;
    Paint mainPaint;
    int width;
    long start, end, fps;

    public SView(Context context) {
        super(context);
        holder = getHolder();
        holder.addCallback(this);
        mainPaint = new Paint();
        mainPaint.setColor(Color.BLACK);
        fps = 0;

    }

    public void surfaceCreated(SurfaceHolder holder) {

        new Thread(){
            public void run() {
                start = System.currentTimeMillis();
                while (true) {
                    end = System.currentTimeMillis();
                    if ((end - start) >= 1000) {
                        Log.d("PERSONAL", "FPS: " + fps + "    milliseconds " + Long.toString(end - start));
                        start = System.currentTimeMillis();
                        fps = 0;
                    }
                    customDraw();
                }
            }
        }.start();
    }

    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {    
    }    

    public void surfaceDestroyed(SurfaceHolder holder) {    
    }

    public void customDraw(){
        mainCanvas = holder.lockCanvas();
        mainCanvas.drawRGB(0,150,0);
        fps++;
        holder.unlockCanvasAndPost(mainCanvas);
    }
}

So my question is how can I solve this problem of having such a horrible fps?

Blorgbeard
  • 101,031
  • 48
  • 228
  • 272
user3843164
  • 369
  • 1
  • 4
  • 14
  • Are you sure you should be getting more than 6 FPS on an emulator? Have you checked for likely config options in the emulator? E.g. hardware acceleration? Are you able to try it on a real device? – Blorgbeard Aug 12 '14 at 03:44
  • No actually I am not sure. I will try it on a real device when I can. I was just hoping someone who's already tried this with an emulator would provide me with some insight. – user3843164 Aug 12 '14 at 03:51
  • try to look at this [wiki](http://stackoverflow.com/questions/1554099/why-is-the-android-emulator-so-slow) – Ker p pag Aug 12 '14 at 03:54
  • Actually sorry for all the trouble everyone I just tried on a real device and got around 50-60 fps. However if I may, it varied quite a lot sometimes going to 48 and then 59, it that normal? Thanks and sorry again – user3843164 Aug 12 '14 at 04:41
  • It's "normal" depending on how fast the device is and how many pixels you're touching. The multi-surface test in Grafika has a "bounce" feature that exercises software rendering; on a Nexus 10 it can't hit 60fps, on a Nexus 5 it hits it easily. – fadden Aug 12 '14 at 15:11
  • What is grafika? Sorry but I have no idea what you're talking about. – user3843164 Aug 12 '14 at 21:10

0 Answers0