60Hz 的动画如何运作?
我正在使用 Thread 在 Android 下进行滚动。 线程运行方法是经典的。我在网上拍的 我的视图是 SurfaceView。
public void run() {
Canvas canvas = null;
while (_run) {
canvas = _surfaceHolder.lockCanvas();
if (canvas != null) {
_surface.doDraw(canvas);
_surfaceHolder.unlockCanvasAndPost(canvas);
}
}
}
我不明白的是: 为什么 doDraw (将在屏幕上绘制)每秒被调用 60 次? 为什么不存在同步问题?
我不知道液晶显示器是如何工作的,但是在屏幕上,如果您在不等待屏幕同步的情况下进行滚动,则可能屏幕顶部显示前一个图像,而底部显示正确的图像。我在 Android 上没有这个问题。
SurfaceView 是否处理一种双缓冲? 如果是这样的话,什么时候翻转完成?
我在互联网上没有找到任何相关信息!
谢谢 艾蒂安
I'm using a Thread to make a scrolling under Android.
The thread run method is classic. I took it on Internet
My view is a SurfaceView.
public void run() {
Canvas canvas = null;
while (_run) {
canvas = _surfaceHolder.lockCanvas();
if (canvas != null) {
_surface.doDraw(canvas);
_surfaceHolder.unlockCanvasAndPost(canvas);
}
}
}
What I do not understand is:
Why the doDraw (that will draw on screen) is called exactly 60 times per second ?
And why there is no synchro problem ?
I do not know how LCD works but on a screen, if you make a scrolling without waiting for the screen synchro, it is possible that the top of the screen display the previous image while the bottom display the correct image. I do not have the problem on Android.
Is it the SurfaceView that handle a kind of double buffering ?
And if it is the case, when the flip is done ?
I do not find any information about that on Internet!
Thank's
Etienne
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它确实是双缓冲的,翻转是在SurfaceHolder.unlockCanvasAndPost()中完成的。
看看这个: http://developer.android .com/reference/android/view/SurfaceHolder.html#unlockCanvasAndPost(android.graphics.Canvas)
[编辑] 抱歉,忘记了您的第一个问题
Android 始终启用垂直同步,因此要么。 lockCanvas() 或unlockCanvasAndPost() 将阻塞剩余时间来同步它。
我不知道我的头脑是否是lockCanvas()或unlockCanvasAndPost()阻塞了,但是应该很容易检查您是否需要它。
It is indeed double buffered, the flip is done in SurfaceHolder.unlockCanvasAndPost().
Check this out: http://developer.android.com/reference/android/view/SurfaceHolder.html#unlockCanvasAndPost(android.graphics.Canvas)
[Edit] Sorry, forgot your first question.
Android always have vsync enabled, and therefore either lockCanvas() or unlockCanvasAndPost() will block the remaining time to sync it.
I don't know im my head if it is lockCanvas() or unlockCanvasAndPost() that blocks, but it should be easy enough to check if you'd need it.
至少在 Android 2.3、SGS 上,锁位于
lockCanvas()
中。我通过在此调用之前和之后调用 System.nanoTime() 来测量它。At least on Android 2.3, SGS, the lock is in
lockCanvas()
. I measured it by callingSystem.nanoTime()
before and after this call.