public void visualize(Canvas canvas, Rect rect) { Paint paint = new Paint { color = Colors.blue }; Paint paint2 = new Paint { color = Colors.red }; Paint paint3 = new Paint { color = Colors.green }; Paint paint4 = new Paint { color = Colors.white70 }; float[] costFrames = this._laps; int curFrame = (this._currentSample - 1) % InstrumentationUtils.kMaxSamples; float barWidth = Mathf.Max(1, rect.width / costFrames.Length); float perHeight = rect.height / 32.0f; canvas.drawRect(rect, paint4); canvas.drawRect(Rect.fromLTWH(rect.left, rect.top + perHeight * 16.0f, rect.width, 1), paint3); float cur_x = rect.left; Path barPath = new Path(); for (var i = 0; i < costFrames.Length; i++) { if (costFrames[i] != 0) { float curHeight = Mathf.Min(perHeight * costFrames[i] * 1000, rect.height); Rect barRect = Rect.fromLTWH(cur_x, rect.top + rect.height - curHeight, barWidth, curHeight); barPath.addRect(barRect); } cur_x += barWidth; } canvas.drawPath(barPath, paint); if (curFrame >= 0 && curFrame < costFrames.Length) { if (costFrames[curFrame] != 0) { float curHeight = Mathf.Min(perHeight * costFrames[curFrame] * 1000, rect.height); Rect barRect = Rect.fromLTWH(rect.left + barWidth * curFrame, rect.top + rect.height - curHeight, barWidth, curHeight); canvas.drawRect(barRect, paint2); } var pb = new ParagraphBuilder(new ParagraphStyle { }); pb.addText("Current Frame Cost: " + costFrames[curFrame] * 1000 + "ms" + " ; Max(in last 120 frames): " + this.maxDelta() * 1000 + "ms"); var paragraph = pb.build(); paragraph.layout(new ParagraphConstraints(width: 800)); canvas.drawParagraph(paragraph, new Offset(rect.left, rect.top + rect.height - 12)); } }
void _drawFrameCost(Canvas canvas, float x, float y, float width, float height) { Rect visualizationRect = Rect.fromLTWH(x, y, width, height); Paint paint = new Paint { color = Colors.blue }; Paint paint2 = new Paint { color = Colors.red }; Paint paint3 = new Paint { color = Colors.green }; Paint paint4 = new Paint { color = Colors.white70 }; float[] costFrames = PerformanceUtils.instance.getFrames(); int curFrame = PerformanceUtils.instance.getCurFrame(); float barWidth = Mathf.Max(1, width / costFrames.Length); float perHeight = height / 32.0f; canvas.drawRect(visualizationRect, paint4); canvas.drawRect(Rect.fromLTWH(x, y + perHeight * 16.0f, width, 1), paint3); float cur_x = x; Path barPath = new Path(); for (var i = 0; i < costFrames.Length; i++) { if (costFrames[i] != 0) { float curHeight = Mathf.Min(perHeight * costFrames[i], height); Rect barRect = Rect.fromLTWH(cur_x, y + height - curHeight, barWidth, curHeight); barPath.addRect(barRect); } cur_x += barWidth; } canvas.drawPath(barPath, paint); if (curFrame >= 0 && curFrame < costFrames.Length && costFrames[curFrame] != 0) { float curHeight = Mathf.Min(perHeight * costFrames[curFrame], height); Rect barRect = Rect.fromLTWH(x + barWidth * curFrame, y + height - curHeight, barWidth, curHeight); canvas.drawRect(barRect, paint2); var pb = new ParagraphBuilder(new ParagraphStyle { }); pb.addText("Frame Cost: " + costFrames[curFrame] + "ms"); var paragraph = pb.build(); paragraph.layout(new ParagraphConstraints(width: 300)); canvas.drawParagraph(paragraph, new Offset(x, y + height - 12)); } }
void _drawFPS(Canvas canvas, float x, float y) { var pb = new ParagraphBuilder(new ParagraphStyle { }); pb.addText("FPS = " + PerformanceUtils.instance.getFPS()); var paragraph = pb.build(); paragraph.layout(new ParagraphConstraints(width: 300)); canvas.drawParagraph(paragraph, new Offset(x, y)); }
public void paint(Canvas canvas, Offset offset) { Debug.Assert(!_needsLayout); canvas.drawParagraph(_paragraph, offset); }