summaryrefslogtreecommitdiff
path: root/apct-tests
diff options
context:
space:
mode:
authorTeng-Hui Zhu <ztenghui@google.com>2016-06-21 15:42:39 -0700
committerTeng-Hui Zhu <ztenghui@google.com>2016-06-22 14:11:37 -0700
commit4cbaff6be1117f32c9706657b3f27c6f77e76492 (patch)
tree2ea28a3a822a939f21cf84e022e46882ff589750 /apct-tests
parent23d1fdded5fe78024927137ddfb82401fd9e3344 (diff)
Create BitmapUtils class for performance apct tests
b/28980976 Change-Id: I3c625f336b6e89352b3906244479da184858cc83
Diffstat (limited to 'apct-tests')
-rw-r--r--apct-tests/perftests/graphics/src/android/graphics/perftests/VectorDrawablePerfTest.java53
-rw-r--r--apct-tests/perftests/utils/src/android/perftests/utils/BitmapUtils.java56
2 files changed, 69 insertions, 40 deletions
diff --git a/apct-tests/perftests/graphics/src/android/graphics/perftests/VectorDrawablePerfTest.java b/apct-tests/perftests/graphics/src/android/graphics/perftests/VectorDrawablePerfTest.java
index 6f17369d80a6..3e8d6d2345ee 100644
--- a/apct-tests/perftests/graphics/src/android/graphics/perftests/VectorDrawablePerfTest.java
+++ b/apct-tests/perftests/graphics/src/android/graphics/perftests/VectorDrawablePerfTest.java
@@ -16,28 +16,24 @@
package android.graphics.perftests;
-import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
+import android.graphics.Color;
import android.graphics.drawable.VectorDrawable;
-import android.os.Bundle;
import android.perftests.utils.BenchmarkState;
+import android.perftests.utils.BitmapUtils;
import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.LargeTest;
-import android.util.Log;
import com.android.frameworks.perftests.R;
-import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
@LargeTest
public class VectorDrawablePerfTest extends ActivityInstrumentationTestCase2<StubActivity> {
- private static final String TAG = "PathPerfTest";
- private static final boolean DBG_PERF = false;
+ private static final boolean DUMP_BITMAP = false;
private int[] mTestWidths = {1024, 512};
private int[] mTestHeights = {512, 1024};
@@ -48,37 +44,8 @@ public class VectorDrawablePerfTest extends ActivityInstrumentationTestCase2<Stu
super(StubActivity.class);
}
- // Save a bitmap into a PNG, only for debugging purpose.
- // TODO: move into utility class.
- private void saveBitmapIntoPNG(Bitmap bitmap, int resId) throws IOException {
- // Save the image to the disk.
- FileOutputStream out = null;
- try {
- String originalFilePath = getActivity().getResources().getString(resId);
- File originalFile = new File(originalFilePath);
- String fileFullName = originalFile.getName();
- String fileTitle = fileFullName.substring(0, fileFullName.lastIndexOf("."));
-
- File externalFilesDir = getActivity().getExternalFilesDir(null);
- File outputFile = new File(externalFilesDir, fileTitle + "_golden.png");
- if (!outputFile.exists()) {
- outputFile.createNewFile();
- }
-
- out = new FileOutputStream(outputFile, false);
- bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
- Log.v(TAG, "Write test No." + outputFile.getAbsolutePath() + " to file successfully.");
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- if (out != null) {
- out.close();
- }
- }
- }
-
@LargeTest
- public void testVectorDrawableInflatePerf() throws IOException {
+ public void testBitmapDrawPerf() throws IOException {
int resId = R.drawable.vector_drawable01;
VectorDrawable vd = (VectorDrawable) getActivity().getDrawable(resId);
@@ -98,9 +65,15 @@ public class VectorDrawablePerfTest extends ActivityInstrumentationTestCase2<Stu
// Double check the bitmap pixels to make sure we draw correct content.
int backgroundColor = bmp.getPixel(w / 4, h / 2);
- int objColor = bmp.getPixel(w / 8, h / 2);
- assertTrue("The background should be white", backgroundColor == 0xFFFFFFFF);
- assertTrue("The object should be black", objColor == 0xFF000000);
+ int objColor = bmp.getPixel(w / 8, h / 2 + 1);
+ int emptyColor = bmp.getPixel(w * 3 / 4, h * 3 / 4);
+ assertTrue("The background should be white", backgroundColor == Color.WHITE);
+ assertTrue("The object should be black", objColor == Color.BLACK);
+ assertTrue("The right bottom part should be empty", emptyColor == Color.TRANSPARENT);
+
+ if (DUMP_BITMAP) {
+ BitmapUtils.saveBitmapIntoPNG(getActivity(), bmp, resId);
+ }
state.sendFullStatusReport(getInstrumentation(), KEY_VECTORDRAWABLE_DRAW_TIME);
}
diff --git a/apct-tests/perftests/utils/src/android/perftests/utils/BitmapUtils.java b/apct-tests/perftests/utils/src/android/perftests/utils/BitmapUtils.java
new file mode 100644
index 000000000000..4d0d97196241
--- /dev/null
+++ b/apct-tests/perftests/utils/src/android/perftests/utils/BitmapUtils.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2016 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 android.perftests.utils;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.util.Log;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+public class BitmapUtils {
+ private static final String TAG = "BitmapUtils";
+
+ public static void saveBitmapIntoPNG(Context context, Bitmap bitmap, int resId) throws IOException {
+ // Save the image to the disk.
+ FileOutputStream out = null;
+ try {
+ String originalFilePath = context.getResources().getString(resId);
+ File originalFile = new File(originalFilePath);
+ String fileFullName = originalFile.getName();
+ String fileTitle = fileFullName.substring(0, fileFullName.lastIndexOf("."));
+
+ File externalFilesDir = context.getExternalFilesDir(null);
+ File outputFile = new File(externalFilesDir, fileTitle + "_generated.png");
+ if (!outputFile.exists()) {
+ outputFile.createNewFile();
+ }
+
+ out = new FileOutputStream(outputFile, false);
+ bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
+ Log.v(TAG, "Write test No." + outputFile.getAbsolutePath() + " to file successfully.");
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ if (out != null) {
+ out.close();
+ }
+ }
+ }
+}