summaryrefslogtreecommitdiffstats
path: root/tests/RenderScriptTests/SceneGraph/src
diff options
context:
space:
mode:
authorAlex Sakhartchouk <alexst@google.com>2012-01-11 17:26:18 -0800
committerAlex Sakhartchouk <alexst@google.com>2012-01-11 17:26:18 -0800
commite57b34155269cc030b4b241f556207f7012a0f07 (patch)
tree0826746011895f76cdcad59d9285400baf2c9aa8 /tests/RenderScriptTests/SceneGraph/src
parentea8345abf7a6ddf827bce91efb3bf049520590b8 (diff)
downloadframeworks_base-e57b34155269cc030b4b241f556207f7012a0f07.zip
frameworks_base-e57b34155269cc030b4b241f556207f7012a0f07.tar.gz
frameworks_base-e57b34155269cc030b4b241f556207f7012a0f07.tar.bz2
Cleanup and refactoring.
Change-Id: I663981416a2f12c627b562eb998255526445235e
Diffstat (limited to 'tests/RenderScriptTests/SceneGraph/src')
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneManager.java48
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestAppLoadingScreen.java6
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestAppRS.java49
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Texture2D.java36
4 files changed, 56 insertions, 83 deletions
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneManager.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneManager.java
index 92cb538..be25356 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneManager.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneManager.java
@@ -16,12 +16,22 @@
package com.android.scenegraph;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.FileInputStream;
+import java.io.BufferedInputStream;
+import java.io.Writer;
+
import java.lang.Math;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+
import android.renderscript.RenderScriptGL;
import android.renderscript.Mesh;
import android.renderscript.*;
@@ -61,6 +71,44 @@ public class SceneManager extends SceneGraphBase {
return false;
}
+ static Bitmap loadBitmap(String name, Resources res) {
+ InputStream is = null;
+ boolean loadFromSD = isSDCardPath(name);
+ try {
+ if (!loadFromSD) {
+ is = res.getAssets().open(name);
+ } else {
+ File f = new File(name);
+ is = new BufferedInputStream(new FileInputStream(f));
+ }
+ } catch (IOException e) {
+ Log.e("ImageLoaderTask", " Message: " + e.getMessage());
+ return null;
+ }
+
+ Bitmap b = BitmapFactory.decodeStream(is);
+ try {
+ is.close();
+ } catch (IOException e) {
+ Log.e("ImageLoaderTask", " Message: " + e.getMessage());
+ }
+ return b;
+ }
+
+ public static Allocation loadCubemap(String name, RenderScriptGL rs, Resources res) {
+ Bitmap b = loadBitmap(name, res);
+ return Allocation.createCubemapFromBitmap(rs, b,
+ MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
+ Allocation.USAGE_GRAPHICS_TEXTURE);
+ }
+
+ public static Allocation loadTexture2D(String name, RenderScriptGL rs, Resources res) {
+ Bitmap b = loadBitmap(name, res);
+ return Allocation.createFromBitmap(rs, b,
+ Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
+ Allocation.USAGE_GRAPHICS_TEXTURE);
+ }
+
public static class SceneLoadedCallback implements Runnable {
Scene mLoadedScene;
String mName;
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestAppLoadingScreen.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestAppLoadingScreen.java
index db238a2..60bdbb9 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestAppLoadingScreen.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestAppLoadingScreen.java
@@ -16,12 +16,6 @@
package com.android.scenegraph;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.FileInputStream;
-import java.io.BufferedInputStream;
-import java.io.Writer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestAppRS.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestAppRS.java
index 9377aa7..fb7f436 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestAppRS.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestAppRS.java
@@ -16,39 +16,27 @@
package com.android.scenegraph;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.FileInputStream;
-import java.io.BufferedInputStream;
-import java.io.Writer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Vector;
+import com.android.scenegraph.SceneManager;
+import com.android.scenegraph.SceneManager.SceneLoadedCallback;
+
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.renderscript.*;
-import android.renderscript.Allocation.MipmapControl;
-import android.renderscript.Element.Builder;
-import android.renderscript.Font.Style;
import android.renderscript.Program.TextureType;
-import android.renderscript.ProgramStore.DepthFunc;
import android.util.Log;
-import com.android.scenegraph.SceneManager.SceneLoadedCallback;
-
// This is where the scenegraph and the rendered objects are initialized and used
public class TestAppRS {
private static String modelName = "orientation_test.dae";
private static String TAG = "TestAppRS";
- private final int STATE_LAST_FOCUS = 1;
- private final boolean mLoadFromSD = true;
- private static String mSDFilePath = "sdcard/scenegraph/";
private static String mFilePath = "";
int mWidth;
@@ -148,38 +136,11 @@ public class TestAppRS {
Allocation tempEnv;
Allocation tempDiff;
- Allocation loadCubemap(String name) {
- InputStream is = null;
- try {
- if (!mLoadFromSD) {
- is = mRes.getAssets().open(name);
- } else {
- File f = new File(mSDFilePath + name);
- is = new BufferedInputStream(new FileInputStream(f));
- }
- } catch (IOException e) {
- Log.e("ImageLoaderTask", " Message: " + e.getMessage());
- return null;
- }
-
- Bitmap b = BitmapFactory.decodeStream(is);
- try {
- is.close();
- } catch (IOException e) {
- Log.e("ImageLoaderTask", " Message: " + e.getMessage());
- }
-
- return Allocation.createCubemapFromBitmap(mRS,
- b,
- MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
- Allocation.USAGE_GRAPHICS_TEXTURE);
- }
-
protected Boolean doInBackground(String... names) {
long start = System.currentTimeMillis();
- tempEnv = loadCubemap("cube_env.png");
- tempDiff = loadCubemap("cube_spec.png");
+ tempEnv = SceneManager.loadCubemap("sdcard/scenegraph/cube_env.png", mRS, mRes);
+ tempDiff = SceneManager.loadCubemap("sdcard/scenegraph/cube_spec.png", mRS, mRes);
long end = System.currentTimeMillis();
Log.v("TIMER", "Image load time: " + (end - start));
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Texture2D.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Texture2D.java
index 8242986..76ac629 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Texture2D.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Texture2D.java
@@ -16,40 +16,26 @@
package com.android.scenegraph;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.FileInputStream;
-import java.io.BufferedInputStream;
import java.lang.Math;
-import java.net.URL;
-import java.util.ArrayList;
+
+import com.android.scenegraph.SceneManager;
import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
import android.renderscript.*;
-import android.renderscript.Allocation.MipmapControl;
-import android.renderscript.Matrix4f;
-import android.renderscript.Type.Builder;
import android.util.Log;
/**
* @hide
*/
public class Texture2D extends SceneGraphBase {
- private boolean mLoadFromSD;
-
String mFileName;
String mFileDir;
Allocation mRsTexture;
public Texture2D() {
- mLoadFromSD = false;
}
public void setFileDir(String dir) {
- mLoadFromSD = SceneManager.isSDCardPath(dir);
mFileDir = dir;
}
@@ -67,24 +53,8 @@ public class Texture2D extends SceneGraphBase {
}
String shortName = mFileName.substring(mFileName.lastIndexOf('/') + 1);
- InputStream is = null;
- try {
- if (!mLoadFromSD) {
- is = res.getAssets().open(mFileDir + shortName);
- } else {
- File f = new File(mFileDir + shortName);
- is = new BufferedInputStream(new FileInputStream(f));
- }
- } catch (IOException e) {
- Log.e("Texture2D",
- "Could not open image file " + shortName + " Message: " + e.getMessage());
- return null;
- }
+ mRsTexture = SceneManager.loadTexture2D(mFileDir + shortName, rs, res);
- Bitmap b = BitmapFactory.decodeStream(is);
- mRsTexture = Allocation.createFromBitmap(rs, b,
- Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
- Allocation.USAGE_GRAPHICS_TEXTURE);
return mRsTexture;
}
}