From 4e9e32572529ffc5bb442fe082206df2285261e3 Mon Sep 17 00:00:00 2001 From: Florin Malita Date: Mon, 7 May 2018 16:30:01 -0400 Subject: [viewer] Avoid per-frame json UI updates The reason we push Json updates for every frame is to support the Android FPS meter - which happens to require the native FPS meter for updates. Instead of supporting two meters: 1) scale up the native FPS widget on Android (1.5x) 2) remove the Android widget 3) stop calling updateUIState() from onPaint() Change-Id: Ica8109869035b2f885743a7e38b50688b69fa5e4 Reviewed-on: https://skia-review.googlesource.com/126621 Reviewed-by: Brian Osman Commit-Queue: Florin Malita --- tools/viewer/StatsLayer.cpp | 15 +++++++++++++++ tools/viewer/Viewer.cpp | 15 --------------- 2 files changed, 15 insertions(+), 15 deletions(-) (limited to 'tools/viewer') diff --git a/tools/viewer/StatsLayer.cpp b/tools/viewer/StatsLayer.cpp index 75226fd7db..50faf9cdd4 100644 --- a/tools/viewer/StatsLayer.cpp +++ b/tools/viewer/StatsLayer.cpp @@ -60,6 +60,13 @@ void StatsLayer::onPaint(SkCanvas* canvas) { fTimers[i].fTimes[fCurrentMeasurement] = 0; } +#ifdef SK_BUILD_FOR_ANDROID + // Scale up the stats overlay on Android devices + static constexpr SkScalar kScale = 1.5; +#else + static constexpr SkScalar kScale = 1; +#endif + // Now draw everything static const float kPixelPerMS = 2.0f; static const int kDisplayWidth = 192; @@ -77,6 +84,14 @@ void StatsLayer::onPaint(SkCanvas* canvas) { SkPaint paint; canvas->save(); + // Scale the canvas while keeping the right edge in place. + canvas->concat(SkMatrix::MakeRectToRect(SkRect::Make(canvasSize), + SkRect::MakeXYWH(canvasSize.width() * (1 - kScale), + 0, + canvasSize.width() * kScale, + canvasSize.height() * kScale), + SkMatrix::kFill_ScaleToFit)); + paint.setColor(SK_ColorBLACK); canvas->drawRect(rect, paint); // draw the 16ms line diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp index b4da7dba64..c47c62fd39 100644 --- a/tools/viewer/Viewer.cpp +++ b/tools/viewer/Viewer.cpp @@ -1144,9 +1144,6 @@ void Viewer::onPaint(SkCanvas* canvas) { fCommands.drawHelp(canvas); this->drawImGui(); - - // Update the FPS - this->updateUIState(); } SkPoint Viewer::mapEvent(float x, float y) { @@ -1811,24 +1808,12 @@ void Viewer::updateUIState() { softkeyState[kOptions].append(Json::Value(softkey.c_str())); } - // FPS state - Json::Value fpsState(Json::objectValue); - fpsState[kName] = kFpsStateName; - double animTime = fStatsLayer.getLastTime(fAnimateTimer); - double paintTime = fStatsLayer.getLastTime(fPaintTimer); - double flushTime = fStatsLayer.getLastTime(fFlushTimer); - fpsState[kValue] = SkStringPrintf("%8.3lf ms\n\nA %8.3lf\nP %8.3lf\nF%8.3lf", - animTime + paintTime + flushTime, - animTime, paintTime, flushTime).c_str(); - fpsState[kOptions] = Json::Value(Json::arrayValue); - Json::Value state(Json::arrayValue); state.append(slideState); state.append(backendState); state.append(msaaState); state.append(prState); state.append(softkeyState); - state.append(fpsState); fWindow->setUIState(state.toStyledString().c_str()); } -- cgit v1.2.3