@Override protected void onDraw(Canvas canvas) { if ((!mDanmakuVisible) && (!mRequestRender)) { super.onDraw(canvas); return; } if (mClearFlag) { DrawHelper.clearCanvas(canvas); mClearFlag = false; } else { if (handler != null) { RenderingState rs = handler.draw(canvas); if (mShowFps) { if (mDrawTimes == null) mDrawTimes = new LinkedList<Long>(); String fps = String.format( Locale.getDefault(), "fps %.2f,time:%d s,cache:%d,miss:%d", fps(), getCurrentTime() / 1000, rs.cacheHitCount, rs.cacheMissCount); DrawHelper.drawFPS(canvas, fps); } } } mRequestRender = false; // 复位 unlockCanvasAndPost(); }
@Override public synchronized long drawDanmakus() { if (!isSurfaceCreated) return 0; long stime = System.currentTimeMillis(); if (!isShown()) return -1; long dtime = 0; Canvas canvas = lockCanvas(); if (canvas != null) { if (handler != null) { handler.draw(canvas); if (mShowFps) { if (mDrawTimes == null) mDrawTimes = new LinkedList<Long>(); dtime = System.currentTimeMillis() - stime; // not so accurate String fps = String.format(Locale.getDefault(), "%02d MS, fps %.2f", dtime, fps()); DrawHelper.drawFPS(canvas, fps); } } if (isSurfaceCreated) unlockCanvasAndPost(canvas); } dtime = System.currentTimeMillis() - stime; return dtime; }