# How can I speed up the shapes drawing on high-density devices?

I have a game that should draw many shapes on the canvas and in every frame these shapes position will change, the game is running smooth but after adding more shapes some jerk arise and it drops some of frames. And this is just happening in high-density devices (more than 320 dpi).

public void run() {
while (mRunning) {
if (mSurfaceHolder.getSurface().isValid()) {

synchronized (mSurfaceHolder){
canvas = mSurfaceHolder.lockCanvas();

canvas.drawColor(Color.BLACK);
drawOnCanvas(canvas);

mSurfaceHolder.unlockCanvasAndPost(canvas);
}
}
}
}


draw function

public void drawOnCanvas(Canvas canvas) {

for (int i = 0; i < obstacles.size(); i++) {
Obstacle obstacle = obstacles.get(i);
x= obstacle.getX();
y=obstacle.getY();

canvas.drawLine(0, 0, x, y, linePaint);
canvas.drawBitmap(bitmap,x,y,null);
}
}


I have created bitmaps in the constructor, initializing all variables out of the game loop, using SurfaceView and implements Runnable, added Thread.sleep(5); to while loop, tried to decrease bitmap size to about 240 bytes, tried to draw circle instead of bitmap again no change.

It's so strange that the drawing function is so slow in high-density devices, I tried to use some bitmaps as buffer and use them in 3 threads but the game sometimes draw on the wrong location. also I think drawing on another bitmap is not a right solution.

How can I speed things up? The quality does not matter, I just need some more speed.