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);
}
//-------------------------------------------------------------------------------
}
//-------------------------------------------------------------------------------