[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 <brianosman@google.com>
Commit-Queue: Florin Malita <fmalita@chromium.org>
This commit is contained in:
Florin Malita 2018-05-07 16:30:01 -04:00 committed by Skia Commit-Bot
parent d3cee17add
commit 4e9e325725
7 changed files with 17 additions and 90 deletions

View File

@ -36,7 +36,6 @@ public class StateAdapter extends BaseAdapter implements AdapterView.OnItemSelec
private static final String VALUE = "value";
private static final String OPTIONS = "options";
private static final String BACKEND_STATE_NAME = "Backend";
private static final String FPS_STATE_NAME = "FPS";
private static final String REFRESH_STATE_NAME = "Refresh";
private static final String ON = "ON";
private static final String OFF = "OFF";
@ -45,11 +44,9 @@ public class StateAdapter extends BaseAdapter implements AdapterView.OnItemSelec
private ViewerActivity mViewerActivity;
private LinearLayout mLayout;
private JSONArray mStateJson;
private TextView mFPSFloatText;
public StateAdapter(ViewerActivity viewerActivity) {
mViewerActivity = viewerActivity;
mFPSFloatText = (TextView) viewerActivity.findViewById(R.id.fpsFloatText);
try {
mStateJson = new JSONArray("[{\"name\": \"Please\", " +
"\"value\": \"Initialize\", \"options\": []}]");
@ -72,10 +69,9 @@ public class StateAdapter extends BaseAdapter implements AdapterView.OnItemSelec
}
// The first list item is the mLayout that contains a list of state items
// The second list item is the toggle for float FPS
@Override
public int getCount() {
return 2;
return 1;
}
@Override
@ -99,19 +95,6 @@ public class StateAdapter extends BaseAdapter implements AdapterView.OnItemSelec
}
return mLayout;
}
case 1: {
View view = LayoutInflater.from(mViewerActivity).inflate(R.layout.fps_toggle, null);
Switch theSwitch = (Switch) view.findViewById(R.id.theSwitch);
theSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mFPSFloatText.setVisibility(isChecked ? View.VISIBLE : View.INVISIBLE);
// Quickly set the bool fRefresh in native Viewer app for continuous refresh
mViewerActivity.onStateChanged(REFRESH_STATE_NAME, isChecked ? ON : OFF);
}
});
return view;
}
default: {
return null;
}
@ -130,12 +113,6 @@ public class StateAdapter extends BaseAdapter implements AdapterView.OnItemSelec
nameText.setText(item.getString(NAME));
if (nameText.getText().equals(FPS_STATE_NAME) && mFPSFloatText != null) {
mFPSFloatText.setText(value);
// Don't show FPS in the drawer. We'll show it in the float text.
itemView.setVisibility(View.GONE);
}
JSONArray options = item.getJSONArray(OPTIONS);
if (options.length() == 0) {
valueText.setText(value);

View File

@ -35,19 +35,6 @@
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</LinearLayout>
<TextView
android:visibility="invisible"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:padding="10dp"
android:background="@android:color/holo_blue_dark"
android:textColor="@android:color/white"
android:text=" 100.000ms"
android:id="@+id/fpsFloatText"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
</LinearLayout>

View File

@ -23,19 +23,6 @@
android:layout_centerHorizontal="true" />
</LinearLayout>
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:padding="10dp"
android:background="@android:color/holo_blue_dark"
android:textColor="@android:color/white"
android:text=" 100.000ms"
android:id="@+id/fpsFloatText"
android:visibility="invisible"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
<!-- The navigation drawer -->

View File

@ -1,23 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginBottom="0dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/float_fps" />
<Switch
android:id="@+id/theSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="0dp" />
</LinearLayout>

View File

@ -2,5 +2,4 @@
<resources>
<string name="drawer_open">Open navigation drawer</string>
<string name="drawer_close">Close navigation drawer</string>
<string name="float_fps">Render time</string>
</resources>
</resources>

View File

@ -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

View File

@ -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());
}