作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
每次我调用这些方法时,都需要 14-20 毫秒才能继续。
Canvas canvas = holder.lockCanvas();
holder.unlockCanvasAndPost(canvas);
这是正常行为吗?我应该采取不同的方法吗?
这是完整的代码
public class Render extends SurfaceView {
Context c = null;
SurfaceHolder holder;
volatile boolean running = true;
public Render(Context c) {
super(c);
this.c = c;
this.holder = getHolder();
}
public void run() {
if(running) {
if(!holder.getSurface().isValid()){
System.out.println("not valid");
return;
}
Canvas canvas = holder.lockCanvas();
holder.unlockCanvasAndPost(canvas);
}
}
}
追踪:
01-05 15:49:20.322: I/System.out(4892): Frame time: 0 ms frame291
01-05 15:49:20.322: I/System.out(4892): not valid
01-05 15:49:20.322: I/System.out(4892): Frame time: 0 ms frame292
01-05 15:49:20.332: I/System.out(4892): Frame time: 2 ms frame293
01-05 15:49:20.357: I/System.out(4892): Frame time: 22 ms frame294
01-05 15:49:20.357: I/System.out(4892): Frame time: 1 ms frame295
01-05 15:49:20.362: I/System.out(4892): Frame time: 1 ms frame296
01-05 15:49:20.367: D/CLIPBOARD(4892): Hide Clipboard dialog at Starting input: finished by someone else... !
01-05 15:49:20.367: I/System.out(4892): Frame time: 8 ms frame297
01-05 15:49:20.377: I/System.out(4892): Frame time: 10 ms frame298
01-05 15:49:20.397: I/System.out(4892): Frame time: 16 ms frame299
01-05 15:49:20.412: I/System.out(4892): Frame time: 16 ms frame300
01-05 15:49:20.427: I/System.out(4892): Frame time: 16 ms frame301
更新
package android.apps.td;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.content.Context;
import android.opengl.GLSurfaceView;
import android.opengl.GLSurfaceView.Renderer;
public class Render extends GLSurfaceView implements Renderer {
private final int MILLION = 1000000;
private long frame;
public Render(Context context) {
super(context);
setRenderer(this);
// TODO Auto-generated constructor stub
}
public void onDrawFrame(GL10 arg0) {
System.out.println("Frame "+(System.nanoTime()-frame)/MILLION+" ms");
frame = System.nanoTime();
}
public void onSurfaceChanged(GL10 gl, int width, int height) {
System.out.println("Surface changed w:"+width+" h:"+height);
}
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
System.out.println("Surface created");
}
}
最佳答案
我发现了这篇文章:http://replicaisland.blogspot.com/2009/10/rendering-with-two-threads.html
eglSwapBuffers() 可能在 onDrawFrame 之后调用并阻塞,直到硬件完成绘制然后交换缓冲区,这需要 16.67 毫秒的最小延迟。
关于android - SurfaceHolder.lockCanvas() 太贵了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8736194/
我是一名优秀的程序员,十分优秀!