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?