summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Chang (bizkit) <bizkit@0xlab.org>2010-09-01 18:21:02 +0800
committerJoseph Chang (bizkit) <bizkit@0xlab.org>2010-09-01 18:21:02 +0800
commiteed1ace3ed0bed43bcbb3e0bb38c2a327b0e03ef (patch)
tree99c1e43b9873b8fb9ff764721b5f62c9753a52ed
parent070e784e21236c44711fd78be2b144854af40a63 (diff)
download0xbench-eed1ace3ed0bed43bcbb3e0bb38c2a327b0e03ef.tar.gz
Add 2D benchmark DrawArc
-rw-r--r--AndroidManifest.xml9
-rw-r--r--res/layout/arc.xml12
-rw-r--r--src/org/zeroxlab/benchmark/Benchmark.java1
-rw-r--r--src/org/zeroxlab/benchmark/CaseDrawArc.java94
-rw-r--r--src/org/zeroxlab/graphics/DrawArc.java66
-rw-r--r--src/org/zeroxlab/graphics/DrawArcView.java77
6 files changed, 259 insertions, 0 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 84b4fc2..9c76722 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -149,6 +149,15 @@
</intent-filter>
</activity>
+ <activity
+ android:name="org.zeroxlab.graphics.DrawArc"
+ android:screenOrientation="portrait"
+ >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ </intent-filter>
+ </activity>
+
</application>
<uses-sdk android:minSdkVersion="7" />
</manifest>
diff --git a/res/layout/arc.xml b/res/layout/arc.xml
new file mode 100644
index 0000000..f4be562
--- /dev/null
+++ b/res/layout/arc.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+
+ <org.zeroxlab.graphics.DrawArcView
+ android:id="@+id/rect"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"/>
+
+</FrameLayout>
diff --git a/src/org/zeroxlab/benchmark/Benchmark.java b/src/org/zeroxlab/benchmark/Benchmark.java
index 19f70d0..0872128 100644
--- a/src/org/zeroxlab/benchmark/Benchmark.java
+++ b/src/org/zeroxlab/benchmark/Benchmark.java
@@ -102,6 +102,7 @@ public class Benchmark extends Activity implements View.OnClickListener {
Case libUbench = new NativeCaseUbench();
mCases.add(new CaseDrawRect());
+ mCases.add(new CaseDrawArc());
mCases.add(libUbench);
// mflops
mCases.add(arith);
diff --git a/src/org/zeroxlab/benchmark/CaseDrawArc.java b/src/org/zeroxlab/benchmark/CaseDrawArc.java
new file mode 100644
index 0000000..33ff1be
--- /dev/null
+++ b/src/org/zeroxlab/benchmark/CaseDrawArc.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2010 0xlab - http://0xlab.org/
+ *
+ * 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 org.zeroxlab.benchmark;
+
+import android.util.Log;
+
+import android.os.SystemClock;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.BroadcastReceiver;
+import android.content.Intent;
+import android.os.Bundle;
+import android.widget.*;
+import android.view.*;
+import java.nio.*;
+import java.util.ArrayList;
+
+public class CaseDrawArc extends Case{
+
+ public static int ArcRound = 500;
+
+ CaseDrawArc() {
+ super("CaseDrawArc", "org.zeroxlab.graphics.DrawArc", 2, ArcRound);
+ mType = "2d-fps";
+ String [] _tmp = {
+ "2d",
+ "render",
+ "skia",
+ "view",
+ };
+ mTags = _tmp;
+ }
+
+ public String getTitle() {
+ return "Draw Arc";
+ }
+
+ public String getDescription() {
+ return "call canvas.drawArc to draw circle for " + ArcRound + " times";
+ }
+
+ @Override
+ public String getBenchmark() {
+ if (!couldFetchReport()) {
+ return "DrawArc has no report";
+ }
+
+ String result = "";
+ long total = 0;
+ int length = mResult.length;
+
+ for (int i = 0; i < length; i++) {
+ float second = (mResult[i] / 1000f);
+ float fps = (float)mCaseRound / second; // milliseconds to seconds
+ result += "Round " + i +": fps = " + fps + "\n";
+ total += fps;
+ }
+
+ result += "Average: fps = " + ((float)total/length) + "\n";
+ return result;
+ }
+
+ @Override
+ public ArrayList<Scenario> getScenarios () {
+ ArrayList<Scenario> scenarios = new ArrayList<Scenario>();
+
+ Scenario s = new Scenario(getTitle(), mType, mTags);
+ s.mLog = getBenchmark();
+ for (int i = 0; i < mResult.length; i++) {
+ float second = (mResult[i] / 1000f);
+ float fps = (float)mCaseRound / second;
+ s.mResults.add(((Float)fps).doubleValue());
+ }
+
+ scenarios.add(s);
+ return scenarios;
+ }
+
+}
diff --git a/src/org/zeroxlab/graphics/DrawArc.java b/src/org/zeroxlab/graphics/DrawArc.java
new file mode 100644
index 0000000..209c439
--- /dev/null
+++ b/src/org/zeroxlab/graphics/DrawArc.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2010 0xlab - http://0xlab.org/
+ *
+ * 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 org.zeroxlab.graphics;
+
+import org.zeroxlab.benchmark.R;
+
+import org.zeroxlab.benchmark.Tester;
+
+import android.app.Activity;
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+
+import android.os.Bundle;
+import android.view.View;
+
+import org.zeroxlab.graphics.DrawArcView;
+
+public class DrawArc extends Tester {
+ /** Called when the activity is first created. */
+
+ private DrawArcView mView;
+
+ public String getTag() {
+ return "DrawArc";
+ }
+
+ public int sleepBeforeStart() {
+ return 1000;
+ }
+
+ public int sleepBetweenRound() {
+ return 0;
+ }
+
+ public void oneRound() {
+ mView.doDraw();
+ decreaseCounter();
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.arc);
+
+ mView = (DrawArcView) findViewById(R.id.rect);
+
+ startTester();
+ }
+}
+
diff --git a/src/org/zeroxlab/graphics/DrawArcView.java b/src/org/zeroxlab/graphics/DrawArcView.java
new file mode 100644
index 0000000..05b2060
--- /dev/null
+++ b/src/org/zeroxlab/graphics/DrawArcView.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2007 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 org.zeroxlab.graphics;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.RectF;
+import android.graphics.Color;
+import android.graphics.drawable.Drawable;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.util.AttributeSet;
+import android.view.KeyEvent;
+import android.view.SurfaceHolder;
+import android.view.SurfaceView;
+import android.view.View;
+import android.widget.TextView;
+
+import android.util.Log;
+
+import java.util.ArrayList;
+import java.util.Random;
+
+
+class DrawArcView extends SurfaceView {
+
+ private SurfaceHolder mSurfaceHolder;
+ private int angle = 0;
+ private int step = 5;
+ private boolean center = false;
+
+ protected void doDraw() {
+ Canvas canvas = mSurfaceHolder.lockCanvas();
+ drawArc(canvas);
+ mSurfaceHolder.unlockCanvasAndPost(canvas);
+ }
+
+ private void drawArc(Canvas canvas) {
+ int color = (0x00252525 | new Random().nextInt() ) | Color.BLACK;
+ Paint p = new Paint();
+ p.setAntiAlias(false);
+ p.setStyle(Paint.Style.FILL);
+ p.setColor(color);
+
+ canvas.drawArc(new RectF(0,0, getWidth(), getHeight()), 0, angle, center, p);
+ center = !center;
+ angle += step;
+ if (angle >= 360) {
+ angle = 0;
+ }
+ }
+
+ public DrawArcView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ mSurfaceHolder = getHolder();
+ }
+}
+