summaryrefslogtreecommitdiff
path: root/tests/UiBench
diff options
context:
space:
mode:
authorStan Iliev <stani@google.com>2017-01-27 14:30:23 -0500
committerStan Iliev <stani@google.com>2017-01-31 15:13:08 -0500
commit010b6a58c7d19ba2ef68295819fce00b37595dec (patch)
tree635c9c983220d2eecf3dd972ccd4875e98e17add /tests/UiBench
parentb3231029b5642474264b3d574fb7d5b68b0bfc57 (diff)
Add UiBench jank and macrobench tests for saveLayer performance
Create 2 jank tests and 1 macrobench that measure saveLayer performance: - Fling a ListView, which has a vertical fading edge. - Draw a canvas with 20 saveLayer/restore interleaved with other drawText and drawRect ops. Test: built and ran UiBench jank and macrobench tests. Change-Id: I5a50feb7431d597c92c7a49031505d41f397d175
Diffstat (limited to 'tests/UiBench')
-rw-r--r--tests/UiBench/AndroidManifest.xml16
-rw-r--r--tests/UiBench/src/com/android/test/uibench/FadingEdgeListActivity.java37
-rw-r--r--tests/UiBench/src/com/android/test/uibench/SaveLayerInterleaveActivity.java89
-rw-r--r--tests/UiBench/src/com/android/test/uibench/listview/CompatListActivity.java6
-rw-r--r--tests/UiBench/src/com/android/test/uibench/listview/FadingEdgeListFragment.java31
5 files changed, 178 insertions, 1 deletions
diff --git a/tests/UiBench/AndroidManifest.xml b/tests/UiBench/AndroidManifest.xml
index 07f7617828e5..c20be5141df5 100644
--- a/tests/UiBench/AndroidManifest.xml
+++ b/tests/UiBench/AndroidManifest.xml
@@ -100,6 +100,22 @@
</intent-filter>
</activity>
<activity
+ android:name=".FadingEdgeListActivity"
+ android:label="General/Fading Edge ListView" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="com.android.test.uibench.TEST" />
+ </intent-filter>
+ </activity>
+ <activity
+ android:name=".SaveLayerInterleaveActivity"
+ android:label="General/SaveLayer Animation" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="com.android.test.uibench.TEST" />
+ </intent-filter>
+ </activity>
+ <activity
android:name=".ClippedListActivity"
android:label="General/Clipped ListView"
android:theme="@style/NoActionBar">
diff --git a/tests/UiBench/src/com/android/test/uibench/FadingEdgeListActivity.java b/tests/UiBench/src/com/android/test/uibench/FadingEdgeListActivity.java
new file mode 100644
index 000000000000..3241e669fb1d
--- /dev/null
+++ b/tests/UiBench/src/com/android/test/uibench/FadingEdgeListActivity.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.test.uibench;
+
+import android.support.v4.app.ListFragment;
+import android.widget.ArrayAdapter;
+import android.widget.ListAdapter;
+
+import com.android.test.uibench.listview.CompatListActivity;
+import com.android.test.uibench.listview.FadingEdgeListFragment;
+
+public class FadingEdgeListActivity extends CompatListActivity {
+
+ @Override
+ protected ListAdapter createListAdapter() {
+ return new ArrayAdapter<>(this, android.R.layout.simple_list_item_1,
+ TextUtils.buildSimpleStringList(40));
+ }
+
+ @Override
+ protected ListFragment createListFragment() {
+ return (ListFragment)new FadingEdgeListFragment();
+ }
+}
diff --git a/tests/UiBench/src/com/android/test/uibench/SaveLayerInterleaveActivity.java b/tests/UiBench/src/com/android/test/uibench/SaveLayerInterleaveActivity.java
new file mode 100644
index 000000000000..eec91cb38066
--- /dev/null
+++ b/tests/UiBench/src/com/android/test/uibench/SaveLayerInterleaveActivity.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.test.uibench;
+
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.ColorFilter;
+import android.graphics.Paint;
+import android.graphics.PixelFormat;
+import android.graphics.Rect;
+import android.graphics.drawable.Drawable;
+import android.os.Bundle;
+import android.support.v7.app.AppCompatActivity;
+
+/**
+ * Test Canvas.saveLayer performance by interleaving drawText/drawRect with saveLayer.
+ * This test will be used to measure if drawing interleaved layers at the beginning of a frame will
+ * decrease FBO switching overhead (this is a future optimization in SkiaGL rendering pipeline).
+ */
+public class SaveLayerInterleaveActivity extends AppCompatActivity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ getWindow().setBackgroundDrawable(new Drawable() {
+ private final Paint mBluePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
+ private final Paint mGreenPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
+
+ @Override
+ public void setAlpha(int alpha) {
+ }
+
+ @Override
+ public int getOpacity() {
+ return PixelFormat.OPAQUE;
+ }
+
+ @Override
+ public void setColorFilter(ColorFilter colorFilter) {
+ }
+
+ @Override
+ public void draw(Canvas canvas) {
+ canvas.drawColor(Color.RED);
+
+ Rect bounds = getBounds();
+ int regions = 20;
+ int smallRectHeight = (bounds.height()/regions);
+ int padding = smallRectHeight / 4;
+ int top = bounds.top;
+ mBluePaint.setColor(Color.BLUE);
+ mBluePaint.setTextSize(padding);
+ mGreenPaint.setColor(Color.GREEN);
+ mGreenPaint.setTextSize(padding);
+
+ //interleave drawText and drawRect with saveLayer ops
+ for (int i = 0; i < regions; i++, top += smallRectHeight) {
+ canvas.saveLayer(bounds.left, top, bounds.right, top + padding,
+ mBluePaint);
+ canvas.drawColor(Color.YELLOW);
+ canvas.drawText("offscreen line "+ i, bounds.left, top + padding,
+ mBluePaint);
+ canvas.restore();
+
+ Rect partX = new Rect(bounds.left, top + padding,
+ bounds.right,top + smallRectHeight - padding);
+ canvas.drawRect(partX, mBluePaint);
+ canvas.drawText("onscreen line "+ i, bounds.left,
+ top + smallRectHeight - padding, mGreenPaint);
+ }
+
+ invalidateSelf();
+ }
+ });
+ }
+}
diff --git a/tests/UiBench/src/com/android/test/uibench/listview/CompatListActivity.java b/tests/UiBench/src/com/android/test/uibench/listview/CompatListActivity.java
index 214c07463fd7..bb7f4a302f8c 100644
--- a/tests/UiBench/src/com/android/test/uibench/listview/CompatListActivity.java
+++ b/tests/UiBench/src/com/android/test/uibench/listview/CompatListActivity.java
@@ -29,11 +29,15 @@ public abstract class CompatListActivity extends AppCompatActivity {
FragmentManager fm = getSupportFragmentManager();
if (fm.findFragmentById(android.R.id.content) == null) {
- ListFragment listFragment = new ListFragment();
+ ListFragment listFragment = createListFragment();
listFragment.setListAdapter(createListAdapter());
fm.beginTransaction().add(android.R.id.content, listFragment).commit();
}
}
protected abstract ListAdapter createListAdapter();
+
+ protected ListFragment createListFragment() {
+ return new ListFragment();
+ }
}
diff --git a/tests/UiBench/src/com/android/test/uibench/listview/FadingEdgeListFragment.java b/tests/UiBench/src/com/android/test/uibench/listview/FadingEdgeListFragment.java
new file mode 100644
index 000000000000..a018b40e8528
--- /dev/null
+++ b/tests/UiBench/src/com/android/test/uibench/listview/FadingEdgeListFragment.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.test.uibench.listview;
+
+import android.os.Bundle;
+import android.support.v4.app.ListFragment;
+import android.widget.ListView;
+
+public class FadingEdgeListFragment extends ListFragment {
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ ListView listView = getListView();
+ listView.setVerticalFadingEdgeEnabled(true);
+ listView.setFadingEdgeLength(500);
+ super.onActivityCreated(savedInstanceState);
+ }
+}