为什么lockCanvas需要这么长时间才能锁定?

时间:2018-05-30 17:48:37

标签: android

我有一个SurfaceView对象,其draw方法被for循环内的1个线程调用约600次。在此期间没有其他线程调用draw

绘制方法:

public void draw() {
    if(this.surface_created){
        long now = System.nanoTime();
        Canvas canvas = holder.lockCanvas();
        Log.d("GAME_SURFACE", "Time to lock:" + (System.nanoTime()-now));
        if (canvas == null)
        {
            System.out.println("[GameSurface] Cannot draw onto canvas as it's null");
        }
        else
        {

            canvas.drawBitmap(this.bitmap, null, this.dest, null);
        }
        holder.unlockCanvasAndPost(canvas);
    }
    else{
        System.out.println("[GameSurface] SURFACE NOT CREATED YET.");
    }

}

当我使用holder.lockCanvas时会出现问题,这需要大约1400万纳秒。因此,要绘制所有位图,最终需要13秒才能完成。为什么需要这么长时间?有解决方法吗?

0 个答案:

没有答案
相关问题