Add 2D benchmark DrawImage
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 20b500f..b10971b 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -176,6 +176,15 @@
</intent-filter>
</activity>
+ <activity
+ android:name="org.zeroxlab.graphics.DrawImage"
+ 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
index f4be562..222e432 100644
--- a/res/layout/arc.xml
+++ b/res/layout/arc.xml
@@ -5,7 +5,7 @@
android:layout_height="fill_parent">
<org.zeroxlab.graphics.DrawArcView
- android:id="@+id/rect"
+ android:id="@+id/arc"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
diff --git a/res/layout/image.xml b/res/layout/image.xml
new file mode 100644
index 0000000..bfa457f
--- /dev/null
+++ b/res/layout/image.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.DrawImageView
+ android:id="@+id/image"
+ 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 0810672..0ed4616 100644
--- a/src/org/zeroxlab/benchmark/Benchmark.java
+++ b/src/org/zeroxlab/benchmark/Benchmark.java
@@ -101,6 +101,7 @@
Case libMicro = new NativeCaseMicro();
Case libUbench = new NativeCaseUbench();
+ mCases.add(new CaseDrawImage());
mCases.add(new CaseDrawRect());
mCases.add(new CaseDrawArc());
mCases.add(new CaseDrawText());
diff --git a/src/org/zeroxlab/benchmark/CaseDrawImage.java b/src/org/zeroxlab/benchmark/CaseDrawImage.java
new file mode 100644
index 0000000..b947c15
--- /dev/null
+++ b/src/org/zeroxlab/benchmark/CaseDrawImage.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 CaseDrawImage extends Case{
+
+ public static int ImageRound = 500;
+
+ CaseDrawImage() {
+ super("CaseDrawImage", "org.zeroxlab.graphics.DrawImage", 2, ImageRound);
+ mType = "2d-fps";
+ String [] _tmp = {
+ "2d",
+ "render",
+ "skia",
+ "view",
+ };
+ mTags = _tmp;
+ }
+
+ public String getTitle() {
+ return "Draw Image";
+ }
+
+ public String getDescription() {
+ return "call canvas.drawImage to draw icon for " + ImageRound + " times";
+ }
+
+ @Override
+ public String getBenchmark() {
+ if (!couldFetchReport()) {
+ return "DrawImage 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
index 209c439..1ee495a 100644
--- a/src/org/zeroxlab/graphics/DrawArc.java
+++ b/src/org/zeroxlab/graphics/DrawArc.java
@@ -58,7 +58,7 @@
super.onCreate(savedInstanceState);
setContentView(R.layout.arc);
- mView = (DrawArcView) findViewById(R.id.rect);
+ mView = (DrawArcView) findViewById(R.id.arc);
startTester();
}
diff --git a/src/org/zeroxlab/graphics/DrawImage.java b/src/org/zeroxlab/graphics/DrawImage.java
new file mode 100644
index 0000000..a5c8581
--- /dev/null
+++ b/src/org/zeroxlab/graphics/DrawImage.java
@@ -0,0 +1,70 @@
+/*
+ * 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 android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+
+import org.zeroxlab.graphics.DrawImageView;
+
+public class DrawImage extends Tester {
+ /** Called when the activity is first created. */
+
+ private DrawImageView mView;
+
+ public String getTag() {
+ return "DrawImage";
+ }
+
+ 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.image);
+
+ mView = (DrawImageView) findViewById(R.id.image);
+ Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
+ mView.setImage(bmp);
+
+ startTester();
+ }
+}
+
diff --git a/src/org/zeroxlab/graphics/DrawImageView.java b/src/org/zeroxlab/graphics/DrawImageView.java
new file mode 100644
index 0000000..88c0379
--- /dev/null
+++ b/src/org/zeroxlab/graphics/DrawImageView.java
@@ -0,0 +1,94 @@
+/*
+ * 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 org.zeroxlab.benchmark.R;
+
+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.Bitmap;
+import android.graphics.BitmapFactory;
+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 DrawImageView extends SurfaceView {
+
+ private SurfaceHolder mSurfaceHolder;
+ private int position[] = {0,0,0,0,0};
+ private boolean direction[] = {true,true,true,true,true};
+ private Bitmap mBitmap;
+ private Paint bgPaint;
+
+ protected void setImage(Bitmap bmp) {
+ mBitmap = bmp;
+ }
+
+ protected void doDraw() {
+ Canvas canvas = mSurfaceHolder.lockCanvas();
+ drawImage(canvas);
+ mSurfaceHolder.unlockCanvasAndPost(canvas);
+ }
+
+ private void drawImage(Canvas canvas) {
+ canvas.drawRect(0,0,getWidth(),getHeight(),bgPaint);
+
+ for(int x=0; x<5; x++) {
+ int speed = (x+1) * 2;
+
+ canvas.drawBitmap(mBitmap, (getWidth() - mBitmap.getWidth())/2, position[x], null);
+ if(direction[x]) {
+ position[x] += speed;
+ if (position[x] + mBitmap.getHeight() >= getHeight())
+ direction[x] = !direction[x];
+ } else {
+ position[x] -= speed;
+ if (position[x] <= 0)
+ direction[x] = !direction[x];
+ }
+
+ }
+ }
+
+ public DrawImageView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ mSurfaceHolder = getHolder();
+ bgPaint = new Paint();
+ bgPaint.setColor(Color.BLACK);
+ bgPaint.setStyle(Paint.Style.FILL);
+ }
+}
+