2012-12-04 8 views
0

SurfaceView에 문제가 있습니다.더 빨리 그릴 방법은? SurfaceView, SurfaceHolder 더러워진 부분

함수 DrawWave는 타이머 간격 5ms로 호출하지만 사실 두 번의 호출 사이에 30ms 이상이 필요합니다 (drawColor, drawPath 삭제 시도).

더티 직사각형을 사용하여 "모드 1"과 "모드 2"로 시도 했으므로 더 빠르게 실행할 수 있기를 바랍니다. 간격은 30ms 이상입니다. (너비는 800px이고 eScrX-sScrX는 < 20px입니다.)

질문 1 : SurfaceView/SurfaceHolder를 사용하여 잘못 했습니까?

질문 2 : 드로잉 속도를 향상 시키려면 어떻게해야합니까? 나는 그것이 10ms 안에 그림을 끝낼 수 있기를 바랍니다.

내 코드 :

public class VS_VChannel extends SurfaceView 
{//Wave Show Class 
    //------------------------------------------------------------------------------- 
    private Paint paint = new Paint(); 
    private SurfaceHolder sHolder = null; 
    private Canvas cvs = null; 
    private Path P = new Path(); 
    //Data source of the wave point Y 
    protected VSChannel Channel = null; 
    private float drawY; 
    //------------------------------------------------------------------------------- 
    public VS_VChannel(Context context) 
    { 
     super(context); 
    } 
    //------------------------------------------------------------------------------ 
    public VS_VChannel(Context context, AttributeSet attrs) 
    { 
     super(context, attrs); 
     //Bind the wave data source whith AttributeSet name:vs_wave 
     String vsName = attrs.getAttributeValue(null, "vs_wave"); 
     Channel = (VSChannel)VS.GetItem(vsName);//Find the wave data source from collection with name 
     // 
     paint.setAntiAlias(true);   
     paint.setDither(true); 
     paint.setColor(Channel.getColor()); 
     paint.setStyle(Paint.Style.STROKE);  
     paint.setStrokeWidth(2);     
     // 
     sHolder = this.getHolder(); 
     this.setZOrderOnTop(true); 
     sHolder.setFormat(PixelFormat.TRANSPARENT); 
    } 
    //------------------------------------------------------------------------------ 
    /** DrawWave is Call by a timer Interval 5ms, 
    * BUT actually it need more than 30ms between twice call,(tried delete drawColor, drawPath) 
    * I try as "Mode 1" and "Mode 2", by using Dirty rect, hope it can run faster 
    * The Interval is the same, both more than 30ms, 
    * (The width of this is 800px, and eScrX-sScrX<20px) 
    */ 
    protected void DrawWave(int sScrX, int eScrX) 
    { 
     Rect rect = new Rect(sScrX, 0, eScrX+8, getHeight()); //Mode 1  
     //Rect rect = new Rect(0, 0, getWidth(), getHeight()); //Mode 2 
     // 
     cvs = sHolder.lockCanvas(rect);  
     cvs.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); 
     cvs.drawPath(P, paint); 
     sHolder.unlockCanvasAndPost(cvs); 
    } 
    //------------------------------------------------------------------------------- 
    protected void GetWaveY() 
    { 
     drawY = Channel.GetWaveY(getHeight()); 
    } 
    //------------------------------------------------------------------------------- 
    protected void MoveTo(float x) 
    { 
     P.moveTo(x, drawY); 
    } 
    //------------------------------------------------------------------------------- 
    protected void LineTo(float x) 
    { 
     P.lineTo(x, drawY); 
    } 
    //------------------------------------------------------------------------------- 
    protected void DrawReturn() 
    { 
     P.reset();//Clear 
     P.moveTo(0, drawY); 
    } 
    //------------------------------------------------------------------------------- 
} 
//------------------------------------------------------------------------------- 

답변

0

당신이, 당신은 단지 과정을 할 수있는 최대한 빨리 스레드가 허용하는 그릴 디스플레이 스레드의 상단에 실행하는 경우. 다른 스레드에서 비트 맵으로 그리기를 제안한 다음 서피스 홀더를 사용하여 잠금 해제, 비트 맵 그리기 및 게시를 제안 할 수 있습니다.