summaryrefslogtreecommitdiffstats
path: root/tests/RenderScriptTests
diff options
context:
space:
mode:
authorXia Wang <xiaw@google.com>2011-06-15 15:34:20 -0700
committerXia Wang <xiaw@google.com>2011-06-15 17:51:52 -0700
commit2dc7afd9c4307fba45120371abbf8b953d33a6b0 (patch)
tree985512951bb3bfc2b384836e41c7b6021d6f4b88 /tests/RenderScriptTests
parentfa59d178bb9421218e18fc60d8ba63eb258cf84a (diff)
downloadframeworks_base-2dc7afd9c4307fba45120371abbf8b953d33a6b0.zip
frameworks_base-2dc7afd9c4307fba45120371abbf8b953d33a6b0.tar.gz
frameworks_base-2dc7afd9c4307fba45120371abbf8b953d33a6b0.tar.bz2
Add opengl bench mark test:
-- display icons with livewallpaper background (galaxy) Change-Id: I5b49bc732180069957abb47d206b5849c47469df
Diffstat (limited to 'tests/RenderScriptTests')
-rw-r--r--tests/RenderScriptTests/PerfTest/res/drawable/flares.pngbin0 -> 413 bytes
-rw-r--r--tests/RenderScriptTests/PerfTest/res/drawable/light1.jpgbin0 -> 11314 bytes
-rw-r--r--tests/RenderScriptTests/PerfTest/res/drawable/space.jpgbin0 -> 137126 bytes
-rw-r--r--tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchRS.java127
-rw-r--r--tests/RenderScriptTests/PerfTest/src/com/android/perftest/rsbench.rs219
5 files changed, 342 insertions, 4 deletions
diff --git a/tests/RenderScriptTests/PerfTest/res/drawable/flares.png b/tests/RenderScriptTests/PerfTest/res/drawable/flares.png
new file mode 100644
index 0000000..3a5c970
--- /dev/null
+++ b/tests/RenderScriptTests/PerfTest/res/drawable/flares.png
Binary files differ
diff --git a/tests/RenderScriptTests/PerfTest/res/drawable/light1.jpg b/tests/RenderScriptTests/PerfTest/res/drawable/light1.jpg
new file mode 100644
index 0000000..2f2f10e
--- /dev/null
+++ b/tests/RenderScriptTests/PerfTest/res/drawable/light1.jpg
Binary files differ
diff --git a/tests/RenderScriptTests/PerfTest/res/drawable/space.jpg b/tests/RenderScriptTests/PerfTest/res/drawable/space.jpg
new file mode 100644
index 0000000..b61f6a3
--- /dev/null
+++ b/tests/RenderScriptTests/PerfTest/res/drawable/space.jpg
Binary files differ
diff --git a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchRS.java b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchRS.java
index 5ca49ad..3f57799 100644
--- a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchRS.java
+++ b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchRS.java
@@ -38,6 +38,10 @@ import android.renderscript.ProgramStore.BlendSrcFunc;
import android.renderscript.ProgramStore.BlendDstFunc;
import android.renderscript.RenderScript.RSMessageHandler;
import android.renderscript.Sampler.Value;
+import android.renderscript.Mesh.Primitive;
+import android.renderscript.Matrix4f;
+import android.renderscript.ProgramVertexFixedFunction;
+
import android.util.Log;
@@ -47,7 +51,7 @@ public class RsBenchRS {
private static final String SAMPLE_TEXT = "Bench Test";
private static final String LIST_TEXT =
"This is a sample list of text to show in the list view";
-
+ private static int PARTICLES_COUNT = 12000;
int mWidth;
int mHeight;
int mLoops;
@@ -84,6 +88,7 @@ public class RsBenchRS {
private Sampler mLinearWrap;
private Sampler mMipLinearWrap;
private Sampler mNearestClamp;
+ private Sampler mNearesWrap;
private ProgramStore mProgStoreBlendNoneDepth;
private ProgramStore mProgStoreBlendNone;
@@ -108,6 +113,7 @@ public class RsBenchRS {
private ScriptField_VertexShaderConstants3_s mVSConstPixel;
private ScriptField_FragentShaderConstants3_s mFSConstPixel;
+
private ProgramRaster mCullBack;
private ProgramRaster mCullFront;
private ProgramRaster mCullNone;
@@ -123,6 +129,7 @@ public class RsBenchRS {
private Mesh mWbyHMesh;
private Mesh mTorus;
private Mesh mSingleMesh;
+ private Mesh mParticlesMesh;
Font mFontSans;
Font mFontSerif;
@@ -131,6 +138,8 @@ public class RsBenchRS {
private ScriptField_ListAllocs_s mTextureAllocs;
private ScriptField_ListAllocs_s mSampleTextAllocs;
private ScriptField_ListAllocs_s mSampleListViewAllocs;
+ private ScriptField_VpConsts mPvStarAlloc;
+
private ScriptC_rsbench mScript;
@@ -303,6 +312,15 @@ public class RsBenchRS {
mScript.set_gProgStoreBlendNone(mProgStoreBlendNone);
mScript.set_gProgStoreBlendAlpha(mProgStoreBlendAlpha);
mScript.set_gProgStoreBlendAdd(mProgStoreBlendAdd);
+
+ // For GALAXY
+ builder = new ProgramStore.Builder(mRS);
+ builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ZERO);
+ mRS.bindProgramStore(builder.create());
+
+ builder.setBlendFunc(BlendSrcFunc.SRC_ALPHA, BlendDstFunc.ONE);
+ mScript.set_gPSLights(builder.create());
+
}
private void initProgramFragment() {
@@ -319,8 +337,59 @@ public class RsBenchRS {
mScript.set_gProgFragmentColor(mProgFragmentColor);
mScript.set_gProgFragmentTexture(mProgFragmentTexture);
+
+
+ // For Galaxy live wallpaper drawing
+ ProgramFragmentFixedFunction.Builder builder = new ProgramFragmentFixedFunction.Builder(mRS);
+ builder.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE,
+ ProgramFragmentFixedFunction.Builder.Format.RGB, 0);
+ ProgramFragment pfb = builder.create();
+ pfb.bindSampler(mNearesWrap, 0);
+ mScript.set_gPFBackground(pfb);
+
+ builder = new ProgramFragmentFixedFunction.Builder(mRS);
+ builder.setPointSpriteTexCoordinateReplacement(true);
+ builder.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.MODULATE,
+ ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
+ builder.setVaryingColor(true);
+ ProgramFragment pfs = builder.create();
+ pfs.bindSampler(mMipLinearWrap, 0);
+ mScript.set_gPFStars(pfs);
+
}
+ private Matrix4f getProjectionNormalized(int w, int h) {
+ // range -1,1 in the narrow axis at z = 0.
+ Matrix4f m1 = new Matrix4f();
+ Matrix4f m2 = new Matrix4f();
+
+ if(w > h) {
+ float aspect = ((float)w) / h;
+ m1.loadFrustum(-aspect,aspect, -1,1, 1,100);
+ } else {
+ float aspect = ((float)h) / w;
+ m1.loadFrustum(-1,1, -aspect,aspect, 1,100);
+ }
+
+ m2.loadRotate(180, 0, 1, 0);
+ m1.loadMultiply(m1, m2);
+
+ m2.loadScale(-2, 2, 1);
+ m1.loadMultiply(m1, m2);
+
+ m2.loadTranslate(0, 0, 2);
+ m1.loadMultiply(m1, m2);
+ return m1;
+ }
+
+ private void updateProjectionMatrices() {
+ Matrix4f projNorm = getProjectionNormalized(mBenchmarkDimX, mBenchmarkDimY);
+ ScriptField_VpConsts.Item i = new ScriptField_VpConsts.Item();
+ i.Proj = projNorm;
+ i.MVP = projNorm;
+ mPvStarAlloc.set(i, 0, true);
+ }
+
private void initProgramVertex() {
ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(mRS);
mProgVertex = pvb.create();
@@ -332,6 +401,39 @@ public class RsBenchRS {
mPVA.setProjection(proj);
mScript.set_gProgVertex(mProgVertex);
+
+ // For galaxy live wallpaper
+ mPvStarAlloc = new ScriptField_VpConsts(mRS, 1);
+ mScript.bind_vpConstants(mPvStarAlloc);
+ updateProjectionMatrices();
+
+ ProgramVertex.Builder sb = new ProgramVertex.Builder(mRS);
+ String t = "varying vec4 varColor;\n" +
+ "varying vec2 varTex0;\n" +
+ "void main() {\n" +
+ " float dist = ATTRIB_position.y;\n" +
+ " float angle = ATTRIB_position.x;\n" +
+ " float x = dist * sin(angle);\n" +
+ " float y = dist * cos(angle) * 0.892;\n" +
+ " float p = dist * 5.5;\n" +
+ " float s = cos(p);\n" +
+ " float t = sin(p);\n" +
+ " vec4 pos;\n" +
+ " pos.x = t * x + s * y;\n" +
+ " pos.y = s * x - t * y;\n" +
+ " pos.z = ATTRIB_position.z;\n" +
+ " pos.w = 1.0;\n" +
+ " gl_Position = UNI_MVP * pos;\n" +
+ " gl_PointSize = ATTRIB_color.a * 10.0;\n" +
+ " varColor.rgb = ATTRIB_color.rgb;\n" +
+ " varColor.a = 1.0;\n" +
+ "}\n";
+ sb.setShader(t);
+ sb.addInput(mParticlesMesh.getVertexAllocation(0).getType().getElement());
+ sb.addConstant(mPvStarAlloc.getType());
+ ProgramVertex pvs = sb.create();
+ pvs.bindConstants(mPvStarAlloc.getAllocation(), 0);
+ mScript.set_gPVStars(pvs);
}
private void initCustomShaders() {
@@ -429,6 +531,11 @@ public class RsBenchRS {
mScript.set_gTexTransparent(mTexTransparent);
mScript.set_gTexChecker(mTexChecker);
mScript.set_gTexGlobe(mTexGlobe);
+
+ // For Galaxy live wallpaper
+ mScript.set_gTSpace(loadTextureRGB(R.drawable.space));
+ mScript.set_gTLight1(loadTextureRGB(R.drawable.light1));
+ mScript.set_gTFlares(loadTextureARGB(R.drawable.flares));
}
private void initFonts() {
@@ -443,6 +550,19 @@ public class RsBenchRS {
mScript.set_gFontSerif(mFontSerif);
}
+ private void createParticlesMesh() {
+ ScriptField_Particle p = new ScriptField_Particle(mRS, PARTICLES_COUNT);
+
+ final Mesh.AllocationBuilder meshBuilder = new Mesh.AllocationBuilder(mRS);
+ meshBuilder.addVertexAllocation(p.getAllocation());
+ final int vertexSlot = meshBuilder.getCurrentVertexTypeIndex();
+ meshBuilder.addIndexSetType(Primitive.POINT);
+ mParticlesMesh = meshBuilder.create();
+
+ mScript.set_gParticlesMesh(mParticlesMesh);
+ mScript.bind_Particles(p);
+ }
+
private void initMesh() {
m10by10Mesh = getMbyNMesh(mBenchmarkDimX, mBenchmarkDimY, 10, 10);
mScript.set_g10by10Mesh(m10by10Mesh);
@@ -461,6 +581,8 @@ public class RsBenchRS {
mTorus = (Mesh)entry.getObject();
mScript.set_gTorusMesh(mTorus);
}
+
+ createParticlesMesh();
}
private void initSamplers() {
@@ -474,6 +596,7 @@ public class RsBenchRS {
mLinearClamp = Sampler.CLAMP_LINEAR(mRS);
mNearestClamp = Sampler.CLAMP_NEAREST(mRS);
mMipLinearWrap = Sampler.WRAP_LINEAR_MIP_LINEAR(mRS);
+ mNearesWrap = Sampler.WRAP_NEAREST(mRS);
mScript.set_gLinearClamp(mLinearClamp);
mScript.set_gLinearWrap(mLinearWrap);
@@ -527,10 +650,10 @@ public class RsBenchRS {
initSamplers();
initProgramStore();
initProgramFragment();
+ initMesh();
initProgramVertex();
initFonts();
loadImages();
- initMesh();
initProgramRaster();
initCustomShaders();
diff --git a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/rsbench.rs b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/rsbench.rs
index 89c5e5a..6d80b0e 100644
--- a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/rsbench.rs
+++ b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/rsbench.rs
@@ -23,9 +23,50 @@
const int RS_MSG_TEST_DONE = 100;
const int RS_MSG_RESULTS_READY = 101;
-const int gMaxModes = 30;
+const int gMaxModes = 31;
int gMaxLoops;
+// Parameters for galaxy live wallpaper
+rs_allocation gTSpace;
+rs_allocation gTLight1;
+rs_allocation gTFlares;
+rs_mesh gParticlesMesh;
+
+rs_program_fragment gPFBackground;
+rs_program_fragment gPFStars;
+rs_program_vertex gPVStars;
+rs_program_vertex gPVBkProj;
+rs_program_store gPSLights;
+
+float gXOffset = 0.5f;
+
+#define ELLIPSE_RATIO 0.892f
+#define PI 3.1415f
+#define TWO_PI 6.283f
+#define ELLIPSE_TWIST 0.023333333f
+
+static float angle = 50.f;
+static int gOldWidth;
+static int gOldHeight;
+static int gWidth;
+static int gHeight;
+static float gSpeed[12000];
+static int gGalaxyRadius = 300;
+static rs_allocation gParticlesBuffer;
+
+typedef struct __attribute__((packed, aligned(4))) Particle {
+ uchar4 color;
+ float3 position;
+} Particle_t;
+Particle_t *Particles;
+
+typedef struct VpConsts {
+ rs_matrix4x4 Proj;
+ rs_matrix4x4 MVP;
+} VpConsts_t;
+VpConsts_t *vpConstants;
+// End of parameters for galaxy live wallpaper
+
// Allocation to send test names back to java
char *gStringBuffer = 0;
// Allocation to write the results into
@@ -110,6 +151,141 @@ static float textColors[] = {1.0f, 1.0f, 1.0f, 1.0f,
0.5f, 0.6f, 0.7f, 1.0f,
};
+/**
+ * Methods to draw the galaxy live wall paper
+ */
+static float mapf(float minStart, float minStop, float maxStart, float maxStop, float value) {
+ return maxStart + (maxStart - maxStop) * ((value - minStart) / (minStop - minStart));
+}
+
+/**
+ * Helper function to generate the stars.
+ */
+static float randomGauss() {
+ float x1;
+ float x2;
+ float w = 2.f;
+
+ while (w >= 1.0f) {
+ x1 = rsRand(2.0f) - 1.0f;
+ x2 = rsRand(2.0f) - 1.0f;
+ w = x1 * x1 + x2 * x2;
+ }
+
+ w = sqrt(-2.0f * log(w) / w);
+ return x1 * w;
+}
+
+/**
+ * Generates the properties for a given star.
+ */
+static void createParticle(Particle_t *part, int idx, float scale) {
+ float d = fabs(randomGauss()) * gGalaxyRadius * 0.5f + rsRand(64.0f);
+ float id = d / gGalaxyRadius;
+ float z = randomGauss() * 0.4f * (1.0f - id);
+ float p = -d * ELLIPSE_TWIST;
+
+ if (d < gGalaxyRadius * 0.33f) {
+ part->color.x = (uchar) (220 + id * 35);
+ part->color.y = 220;
+ part->color.z = 220;
+ } else {
+ part->color.x = 180;
+ part->color.y = 180;
+ part->color.z = (uchar) clamp(140.f + id * 115.f, 140.f, 255.f);
+ }
+ // Stash point size * 10 in Alpha
+ part->color.w = (uchar) (rsRand(1.2f, 2.1f) * 60);
+
+ if (d > gGalaxyRadius * 0.15f) {
+ z *= 0.6f * (1.0f - id);
+ } else {
+ z *= 0.72f;
+ }
+
+ // Map to the projection coordinates (viewport.x = -1.0 -> 1.0)
+ d = mapf(-4.0f, gGalaxyRadius + 4.0f, 0.0f, scale, d);
+
+ part->position.x = rsRand(TWO_PI);
+ part->position.y = d;
+ gSpeed[idx] = rsRand(0.0015f, 0.0025f) * (0.5f + (scale / d)) * 0.8f;
+
+ part->position.z = z / 5.0f;
+}
+
+/**
+ * Initialize all the starts, called from Java
+ */
+void initParticles() {
+ Particle_t *part = Particles;
+ float scale = gGalaxyRadius / (gWidth * 0.5f);
+ int count = rsAllocationGetDimX(gParticlesBuffer);
+ for (int i = 0; i < count; i ++) {
+ createParticle(part, i, scale);
+ part++;
+ }
+}
+
+static void drawSpace() {
+ rsgBindProgramFragment(gPFBackground);
+ rsgBindTexture(gPFBackground, 0, gTSpace);
+ rsgDrawQuadTexCoords(
+ 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
+ gWidth, 0.0f, 0.0f, 2.0f, 1.0f,
+ gWidth, gHeight, 0.0f, 2.0f, 0.0f,
+ 0.0f, gHeight, 0.0f, 0.0f, 0.0f);
+}
+
+static void drawLights() {
+ rsgBindProgramVertex(gPVBkProj);
+ rsgBindProgramFragment(gPFBackground);
+ rsgBindTexture(gPFBackground, 0, gTLight1);
+
+ float scale = 512.0f / gWidth;
+ float x = -scale - scale * 0.05f;
+ float y = -scale;
+
+ scale *= 2.0f;
+
+ rsgDrawQuad(x, y, 0.0f,
+ x + scale * 1.1f, y, 0.0f,
+ x + scale * 1.1f, y + scale, 0.0f,
+ x, y + scale, 0.0f);
+}
+
+static void drawParticles(float offset) {
+ float a = offset * angle;
+ float absoluteAngle = fabs(a);
+
+ rs_matrix4x4 matrix;
+ rsMatrixLoadTranslate(&matrix, 0.0f, 0.0f, 10.0f - 6.0f * absoluteAngle / 50.0f);
+ if (gHeight > gWidth) {
+ rsMatrixScale(&matrix, 6.6f, 6.0f, 1.0f);
+ } else {
+ rsMatrixScale(&matrix, 12.6f, 12.0f, 1.0f);
+ }
+ rsMatrixRotate(&matrix, absoluteAngle, 1.0f, 0.0f, 0.0f);
+ rsMatrixRotate(&matrix, a, 0.0f, 0.4f, 0.1f);
+ rsMatrixLoad(&vpConstants->MVP, &vpConstants->Proj);
+ rsMatrixMultiply(&vpConstants->MVP, &matrix);
+ rsgAllocationSyncAll(rsGetAllocation(vpConstants));
+
+ rsgBindProgramVertex(gPVStars);
+ rsgBindProgramFragment(gPFStars);
+ rsgBindProgramStore(gPSLights);
+ rsgBindTexture(gPFStars, 0, gTFlares);
+
+ Particle_t *vtx = Particles;
+ int count = rsAllocationGetDimX(gParticlesBuffer);
+ for (int i = 0; i < count; i++) {
+ vtx->position.x = vtx->position.x + gSpeed[i];
+ vtx++;
+ }
+
+ rsgDrawMesh(gParticlesMesh);
+}
+/* end of methods for drawing galaxy */
+
static void setupOffscreenTarget() {
rsgBindColorTarget(gRenderBufferColor, 0);
rsgBindDepthTarget(gRenderBufferDepth);
@@ -333,6 +509,42 @@ static void displayListView() {
}
}
+static void drawGalaxy() {
+ rsgClearColor(0.f, 0.f, 0.f, 1.f);
+ gParticlesBuffer = rsGetAllocation(Particles);
+ rsgBindProgramFragment(gPFBackground);
+
+ gWidth = rsgGetWidth();
+ gHeight = rsgGetHeight();
+ if ((gWidth != gOldWidth) || (gHeight != gOldHeight)) {
+ initParticles();
+ gOldWidth = gWidth;
+ gOldHeight = gHeight;
+ }
+
+ float offset = mix(-1.0f, 1.0f, gXOffset);
+ drawSpace();
+ drawParticles(offset);
+ drawLights();
+}
+
+// Display images and text with live wallpaper in the background
+static void dispalyLiveWallPaper(int wResolution, int hResolution) {
+ bindProgramVertexOrtho();
+
+ drawGalaxy();
+
+ rsgBindProgramStore(gProgStoreBlendAlpha);
+ rsgBindProgramFragment(gProgFragmentTexture);
+ rsgBindSampler(gProgFragmentTexture, 0, gLinearClamp);
+
+ drawMeshInPage(0, 0, wResolution, hResolution);
+ drawMeshInPage(-1.0f*gRenderSurfaceW, 0, wResolution, hResolution);
+ drawMeshInPage(1.0f*gRenderSurfaceW, 0, wResolution, hResolution);
+ drawMeshInPage(-2.0f*gRenderSurfaceW, 0, wResolution, hResolution);
+ drawMeshInPage(2.0f*gRenderSurfaceW, 0, wResolution, hResolution);
+}
+
static float gTorusRotation = 0;
static void updateModelMatrix(rs_matrix4x4 *matrix, void *buffer) {
if (buffer == 0) {
@@ -637,6 +849,7 @@ static const char *testNames[] = {
"UI test with image and text display 3 pages",
"UI test with image and text display 5 pages",
"UI test with list view",
+ "UI test with live wallpaper",
};
void getTestName(int testIndex) {
@@ -744,6 +957,9 @@ static void runTest(int index) {
case 29:
displayListView();
break;
+ case 30:
+ dispalyLiveWallPaper(7, 5);
+ break;
}
}
@@ -767,7 +983,6 @@ static void drawOffscreenResult(int posX, int posY, int width, int height) {
}
int root(void) {
-
gRenderSurfaceW = rsgGetWidth();
gRenderSurfaceH = rsgGetHeight();
rsgClearColor(0.2f, 0.2f, 0.2f, 1.0f);