为什么" SurfaceView"比定制&QUOT慢;查看"? [英] Why "SurfaceView" is slower than a custom "view"?

查看:161
本文介绍了为什么" SurfaceView"比定制&QUOT慢;查看"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发已基本完成的应用程序。但我有一些问题与图形:

I am developing an application that is almost completed. But I have some problems with graphics:

起初我用一个自定义的查看,但遇到了麻烦处理中的设备不同分辨率的时间。另外,动画并不顺利。

Initially I used a custom "View", but had trouble handling the time in different resolutions of devices. Also the animation was not smooth.

所以读了一些例子和评论,我决定使用SurfaceView。现在,动画流畅,但一切要比用查看慢。我不知道为什么,因为我并没有改变几乎没有什么从查看到SurfaceView迁移时:

So there reading some examples and reviews, I decided to use "SurfaceView". Now the animation is smooth, but everything is slower than with a "View". I do not know why, since I did not change practically nothing when migrated from "View" to "SurfaceView":

在视图(+90 FPS):

In "View" (+90 fps):

@Override
public void run(){      
    for(;;){
        if(gameState == PLAYING)
            updatePhisic();                             

        updateSprites();

        this.postInvalidate();
        try{
            Thread.sleep(10);
        }catch(InterruptedException e){}
    }
}

在Surfaceview(Lienzo是主类<Surfaceview>)。(也许每秒30帧)

In "Surfaceview" ("Lienzo" is the main class <"Surfaceview">) (Maybe 30 fps).

@Override
public void run() {
    Canvas canvas;
while(running){
    canvas = null;
    try{
    canvas = holder.lockCanvas(null);
    synchronized(holder){
        lienzo.updatePhisic();
        lienzo.draw(canvas);
    }
    }
        finally{    
        if(canvas != null)
        holder.unlockCanvasAndPost(canvas);
    }
}
}

物理和图形绘制在两种情况下是相同的。

Physics and graphics drawing is the same in both cases.

为什么呢?我的意思是,SurfaceView是显而易见的解决方案的一切,和现在的OpenGL的是解决方案。

Why?, I mean, "SurfaceView" was the apparent solution to everything, and now "OpenGL" is the solution.

感谢。

推荐答案

我也经历了从使用 SurfaceView 切换应用程序的单一时显著FPS增加查看子类。我的看法是,这是由于硬件加速。

I too have experienced a significant FPS increase when switching an application from using SurfaceView to a single View subclass. My belief is that this is due to hardware acceleration.

SurfaceView 开关远的东西我自从与 SurfaceView 的严重错误永远做Android的介绍4.3。请参见的https://$c$c.google.com/ p /安卓/问题/细节?ID = 58385 。在这个Android开发者邮件列表上的讨论,罗曼盖伊居然建议使用普通的查看可能会更快,无论如何,由于硬件加速。事实证明,这是正确的 - 至少在我的设备正在开发的(HTC One X的和老的Nexus 7)。这可能是真实的,但是,图形是为震荡动画更敏感。对我来说,这个FPS增加加糖不必处理 SurfaceView 的bug和重构我的应用程序不使用的最初的痛苦和无奈 SurfaceView

Switching away from SurfaceView is something I had to do ever since the serious bug with SurfaceView was introduced in Android 4.3. See https://code.google.com/p/android/issues/detail?id=58385. During a discussion about this on the Android Developers mailing list, Romain Guy actually suggested that using a normal View might be faster anyway, due to hardware acceleration. This turned out to be true - at least on devices I'm developing on (HTC One X and the old Nexus 7). It could be true, however, that the graphics are more susceptible to 'choppy' animation. For me, this FPS increase sweetened the initial pain and frustration of having to deal with the SurfaceView bug and refactor my application to not use SurfaceView.

这篇关于为什么&QUOT; SurfaceView&QUOT;比定制&QUOT慢;查看&QUOT;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆