summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Chang (bizkit) <bizkit@0xlab.org>2010-09-02 11:59:12 +0800
committerJoseph Chang (bizkit) <bizkit@0xlab.org>2010-09-02 11:59:12 +0800
commite1ce979e8fe59e3fb17181b848d9d0a9a76346db (patch)
tree02f4dc38bb922cfc13c3844524c64d5ae47c0234
parent34342b67c411a2d5fd4964b2e3002a899e9642f8 (diff)
download0xbench-e1ce979e8fe59e3fb17181b848d9d0a9a76346db.tar.gz
Add 2D benchmark DrawCircle2
-rw-r--r--AndroidManifest.xml9
-rw-r--r--res/layout/circle2.xml12
-rw-r--r--src/org/zeroxlab/benchmark/Benchmark.java1
-rw-r--r--src/org/zeroxlab/benchmark/CaseDrawCircle2.java94
-rw-r--r--src/org/zeroxlab/graphics/DrawCircle2.java66
-rw-r--r--src/org/zeroxlab/graphics/DrawCircle2View.java78
6 files changed, 260 insertions, 0 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 97a0fa8..20b500f 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -167,6 +167,15 @@
</intent-filter>
</activity>
+ <activity
+ android:name="org.zeroxlab.graphics.DrawCircle2"
+ 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/circle2.xml b/res/layout/circle2.xml
new file mode 100644
index 0000000..b36c090
--- /dev/null
+++ b/res/layout/circle2.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.DrawCircle2View
+ android:id="@+id/circle2"
+ 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 7f55d3b..0810672 100644
--- a/src/org/zeroxlab/benchmark/Benchmark.java
+++ b/src/org/zeroxlab/benchmark/Benchmark.java
@@ -104,6 +104,7 @@ public class Benchmark extends Activity implements View.OnClickListener {
mCases.add(new CaseDrawRect());
mCases.add(new CaseDrawArc());
mCases.add(new CaseDrawText());
+ mCases.add(new CaseDrawCircle2());
mCases.add(libUbench);
// mflops
mCases.add(arith);
diff --git a/src/org/zeroxlab/benchmark/CaseDrawCircle2.java b/src/org/zeroxlab/benchmark/CaseDrawCircle2.java
new file mode 100644
index 0000000..61c6a12
--- /dev/null
+++ b/src/org/zeroxlab/benchmark/CaseDrawCircle2.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 CaseDrawCircle2 extends Case{
+
+ public static int Circle2Round = 300;
+
+ CaseDrawCircle2() {
+ super("CaseDrawCircle2", "org.zeroxlab.graphics.DrawCircle2", 2, Circle2Round);
+ mType = "2d-fps";
+ String [] _tmp = {
+ "2d",
+ "render",
+ "skia",
+ "view",
+ };
+ mTags = _tmp;
+ }
+
+ public String getTitle() {
+ return "Draw Circle2";
+ }
+
+ public String getDescription() {
+ return "call canvas.drawCircle2 to draw circle for " + Circle2Round + " times";
+ }
+
+ @Override
+ public String getBenchmark() {
+ if (!couldFetchReport()) {
+ return "DrawCircle2 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/DrawCircle2.java b/src/org/zeroxlab/graphics/DrawCircle2.java
new file mode 100644
index 0000000..1fa7757
--- /dev/null
+++ b/src/org/zeroxlab/graphics/DrawCircle2.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.DrawCircle2View;
+
+public class DrawCircle2 extends Tester {
+ /** Called when the activity is first created. */
+
+ private DrawCircle2View mView;
+
+ public String getTag() {
+ return "DrawCircle2";
+ }
+
+ 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.circle2);
+
+ mView = (DrawCircle2View) findViewById(R.id.circle2);
+
+ startTester();
+ }
+}
+
diff --git a/src/org/zeroxlab/graphics/DrawCircle2View.java b/src/org/zeroxlab/graphics/DrawCircle2View.java
new file mode 100644
index 0000000..f4008f9
--- /dev/null
+++ b/src/org/zeroxlab/graphics/DrawCircle2View.java
@@ -0,0 +1,78 @@
+/*
+ * 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 DrawCircle2View extends SurfaceView {
+
+ private SurfaceHolder mSurfaceHolder;
+
+ protected void doDraw() {
+ Canvas canvas = mSurfaceHolder.lockCanvas();
+ drawCircle(canvas);
+ mSurfaceHolder.unlockCanvasAndPost(canvas);
+ }
+
+ private void drawCircle(Canvas canvas) {
+ Random mRandom = new Random();
+
+ int color = (0x00252525 | mRandom.nextInt() ) | Color.BLACK;
+ Paint p = new Paint();
+ p.setAntiAlias(false);
+ p.setStyle(Paint.Style.FILL);
+ p.setColor(color);
+
+ int height = getHeight();
+ int width = getWidth();
+
+ int cx = (int)((mRandom.nextInt() % (width*0.8) ) + (width*0.1));
+ int cy = (int)((mRandom.nextInt() % (height*0.8) ) + (height*0.1));
+ int r = (int)((mRandom.nextInt() % (width*0.4) ) + (width*0.1));
+
+ canvas.drawCircle(cx, cy, r, p);
+ }
+
+ public DrawCircle2View(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ mSurfaceHolder = getHolder();
+ }
+}
+