summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Chang (bizkit) <bizkit@0xlab.org>2010-09-01 18:48:18 +0800
committerJoseph Chang (bizkit) <bizkit@0xlab.org>2010-09-01 18:48:18 +0800
commit4078cc8ecf25a8fe0cb51062ce5c3ea949c62989 (patch)
treef22dca5c32e6be36a8289c068abea83a83247756
parenteed1ace3ed0bed43bcbb3e0bb38c2a327b0e03ef (diff)
download0xbench-4078cc8ecf25a8fe0cb51062ce5c3ea949c62989.tar.gz
Add 2D benchmark DrawText
-rw-r--r--AndroidManifest.xml9
-rw-r--r--res/layout/text.xml12
-rw-r--r--src/org/zeroxlab/benchmark/Benchmark.java1
-rw-r--r--src/org/zeroxlab/benchmark/CaseDrawText.java94
-rw-r--r--src/org/zeroxlab/graphics/DrawText.java66
-rw-r--r--src/org/zeroxlab/graphics/DrawTextView.java105
6 files changed, 287 insertions, 0 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 9c76722..97a0fa8 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -158,6 +158,15 @@
</intent-filter>
</activity>
+ <activity
+ android:name="org.zeroxlab.graphics.DrawText"
+ 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/text.xml b/res/layout/text.xml
new file mode 100644
index 0000000..73dbdac
--- /dev/null
+++ b/res/layout/text.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.DrawTextView
+ android:id="@+id/text"
+ 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 0872128..7f55d3b 100644
--- a/src/org/zeroxlab/benchmark/Benchmark.java
+++ b/src/org/zeroxlab/benchmark/Benchmark.java
@@ -103,6 +103,7 @@ public class Benchmark extends Activity implements View.OnClickListener {
mCases.add(new CaseDrawRect());
mCases.add(new CaseDrawArc());
+ mCases.add(new CaseDrawText());
mCases.add(libUbench);
// mflops
mCases.add(arith);
diff --git a/src/org/zeroxlab/benchmark/CaseDrawText.java b/src/org/zeroxlab/benchmark/CaseDrawText.java
new file mode 100644
index 0000000..17e559d
--- /dev/null
+++ b/src/org/zeroxlab/benchmark/CaseDrawText.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 CaseDrawText extends Case{
+
+ public static int TextRound = 300;
+
+ CaseDrawText() {
+ super("CaseDrawText", "org.zeroxlab.graphics.DrawText", 3, TextRound);
+ mType = "2d-fps";
+ String [] _tmp = {
+ "2d",
+ "render",
+ "skia",
+ "view",
+ };
+ mTags = _tmp;
+ }
+
+ public String getTitle() {
+ return "Draw Text";
+ }
+
+ public String getDescription() {
+ return "call canvas.drawText to draw circle for " + TextRound + " times";
+ }
+
+ @Override
+ public String getBenchmark() {
+ if (!couldFetchReport()) {
+ return "DrawText 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/DrawText.java b/src/org/zeroxlab/graphics/DrawText.java
new file mode 100644
index 0000000..c00c09e
--- /dev/null
+++ b/src/org/zeroxlab/graphics/DrawText.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.DrawTextView;
+
+public class DrawText extends Tester {
+ /** Called when the activity is first created. */
+
+ private DrawTextView mView;
+
+ public String getTag() {
+ return "DrawText";
+ }
+
+ 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.text);
+
+ mView = (DrawTextView) findViewById(R.id.text);
+
+ startTester();
+ }
+}
+
diff --git a/src/org/zeroxlab/graphics/DrawTextView.java b/src/org/zeroxlab/graphics/DrawTextView.java
new file mode 100644
index 0000000..a4acc50
--- /dev/null
+++ b/src/org/zeroxlab/graphics/DrawTextView.java
@@ -0,0 +1,105 @@
+/*
+ * 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.Rect;
+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 DrawTextView extends SurfaceView {
+
+ public final String TEXT1 = "0xbench";
+ public final String TEXT2 = "0xlab";
+
+ class PaintText {
+ public int x;
+ public int y;
+ public Paint paint;
+ public boolean text;
+ PaintText(Paint paint, int x, int y, boolean text) {
+ this.paint = paint;
+ this.x = x;
+ this.y = y;
+ this.text = text;
+ }
+ }
+
+ private SurfaceHolder mSurfaceHolder;
+ private ArrayList<PaintText> rectengleList = new ArrayList<PaintText>();
+
+ protected void doDraw() {
+ Canvas canvas = mSurfaceHolder.lockCanvas();
+ generateNewText(canvas);
+ mSurfaceHolder.unlockCanvasAndPost(canvas);
+ }
+
+ private void generateNewText(Canvas canvas) {
+ Random mRandom = new Random();
+ 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 color = (0x00353535 | mRandom.nextInt() ) | Color.BLACK;
+ Paint p = new Paint();
+ p.setAntiAlias(false);
+ p.setStyle(Paint.Style.FILL);
+ p.setTextAlign(Paint.Align.CENTER);
+
+ if(mRandom.nextInt()%2 == 0)
+ p.setFakeBoldText(true);
+
+ if(mRandom.nextInt()%2 == 0)
+ p.setTextSkewX((float)-0.35);
+
+ p.setColor(color);
+ p.setTextSize(32 + (mRandom.nextInt()%24));
+
+ if(mRandom.nextInt()%2 == 0)
+ canvas.drawText(TEXT1, cx, cy, p);
+ else
+ canvas.drawText(TEXT2, cx, cy, p);
+ }
+
+ public DrawTextView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ mSurfaceHolder = getHolder();
+ }
+}
+