summaryrefslogtreecommitdiffstats
path: root/libs/rs/java
diff options
context:
space:
mode:
authorJason Sams <rjsams@android.com>2009-07-31 16:26:13 -0700
committerJason Sams <rjsams@android.com>2009-07-31 16:26:13 -0700
commit36e612a488511940b61f09803b270aa1c61b68e0 (patch)
treed127d889ee21474d6fb845a190c87fb12eab2eca /libs/rs/java
parentb5a57ad94388ebcd3717a6970a12449055eadabe (diff)
downloadframeworks_base-36e612a488511940b61f09803b270aa1c61b68e0.zip
frameworks_base-36e612a488511940b61f09803b270aa1c61b68e0.tar.gz
frameworks_base-36e612a488511940b61f09803b270aa1c61b68e0.tar.bz2
Begin splitting up RenderScript.java into seperate classes. First piece split off Element.
Diffstat (limited to 'libs/rs/java')
-rw-r--r--libs/rs/java/Film/src/com/android/film/FilmRS.java55
-rw-r--r--libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java10
-rw-r--r--libs/rs/java/Grass/src/com/android/grass/rs/GrassRS.java13
-rw-r--r--libs/rs/java/Rollo/res/raw/rollo.c3
-rw-r--r--libs/rs/java/Rollo/src/com/android/rollo/RolloMesh.java90
-rw-r--r--libs/rs/java/Rollo/src/com/android/rollo/RolloRS.java31
6 files changed, 45 insertions, 157 deletions
diff --git a/libs/rs/java/Film/src/com/android/film/FilmRS.java b/libs/rs/java/Film/src/com/android/film/FilmRS.java
index 12a14e3..0e5b1bd 100644
--- a/libs/rs/java/Film/src/com/android/film/FilmRS.java
+++ b/libs/rs/java/Film/src/com/android/film/FilmRS.java
@@ -21,22 +21,12 @@ import java.io.Writer;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.drawable.BitmapDrawable;
-import android.graphics.drawable.Drawable;
-import android.os.Handler;
-import android.os.Message;
+import android.util.Log;
+
import android.renderscript.Matrix;
import android.renderscript.ProgramVertexAlloc;
import android.renderscript.RenderScript;
-import android.renderscript.RenderScript.ElementPredefined;
-import android.util.AttributeSet;
-import android.util.Log;
-import android.view.KeyEvent;
-import android.view.MotionEvent;
-import android.view.Surface;
-import android.view.SurfaceHolder;
-import android.view.SurfaceView;
+import android.renderscript.Element;
public class FilmRS {
private final int POS_TRANSLATE = 0;
@@ -76,8 +66,8 @@ public class FilmRS {
private RenderScript mRS;
private RenderScript.Script mScriptStrip;
private RenderScript.Script mScriptImage;
- private RenderScript.Element mElementVertex;
- private RenderScript.Element mElementIndex;
+ private Element mElementVertex;
+ private Element mElementIndex;
private RenderScript.Sampler mSampler;
private RenderScript.ProgramFragmentStore mPFSBackground;
private RenderScript.ProgramFragmentStore mPFSImages;
@@ -166,13 +156,10 @@ public class FilmRS {
private void loadImages() {
mBufferIDs = new int[13];
mImages = new RenderScript.Allocation[13];
- mAllocIDs = mRS.allocationCreatePredefSized(
- RenderScript.ElementPredefined.USER_FLOAT,
- mBufferIDs.length);
-
- RenderScript.ElementPredefined ie =
- RenderScript.ElementPredefined.RGB_565;
+ mAllocIDs = mRS.allocationCreateSized(
+ Element.USER_FLOAT, mBufferIDs.length);
+ Element ie = Element.RGB_565;
mImages[0] = mRS.allocationCreateFromBitmapResourceBoxed(mRes, R.drawable.p01, ie, true);
mImages[1] = mRS.allocationCreateFromBitmapResourceBoxed(mRes, R.drawable.p02, ie, true);
mImages[2] = mRS.allocationCreateFromBitmapResourceBoxed(mRes, R.drawable.p03, ie, true);
@@ -197,9 +184,8 @@ public class FilmRS {
private void initState()
{
mBufferState = new int[10];
- mAllocState = mRS.allocationCreatePredefSized(
- RenderScript.ElementPredefined.USER_FLOAT,
- mBufferState.length);
+ mAllocState = mRS.allocationCreateSized(
+ Element.USER_FLOAT, mBufferState.length);
mBufferState[STATE_TRIANGLE_OFFSET_COUNT] = mFSM.mTriangleOffsetsCount;
mBufferState[STATE_LAST_FOCUS] = -1;
@@ -208,10 +194,8 @@ public class FilmRS {
}
private void initRS() {
- mElementVertex = mRS.elementGetPredefined(
- RenderScript.ElementPredefined.NORM_ST_XYZ_F32);
- mElementIndex = mRS.elementGetPredefined(
- RenderScript.ElementPredefined.INDEX_16);
+ mElementVertex = Element.NORM_ST_XYZ_F32;
+ mElementIndex = Element.INDEX_16;
mRS.triangleMeshBegin(mElementVertex, mElementIndex);
mFSM = new FilmStripMesh();
@@ -231,9 +215,8 @@ public class FilmRS {
mRS.scriptCSetRoot(true);
mScriptStrip = mRS.scriptCCreate();
- mAllocPos = mRS.allocationCreatePredefSized(
- RenderScript.ElementPredefined.USER_FLOAT,
- mBufferPos.length);
+ mAllocPos = mRS.allocationCreateSized(
+ Element.USER_FLOAT, mBufferPos.length);
loadImages();
initState();
@@ -250,15 +233,13 @@ public class FilmRS {
mScriptStrip.bindAllocation(mPVA.mAlloc, 3);
- mAllocOffsets = mRS.allocationCreatePredefSized(
- RenderScript.ElementPredefined.USER_I32,
- mFSM.mTriangleOffsets.length);
+ mAllocOffsets = mRS.allocationCreateSized(
+ Element.USER_I32, mFSM.mTriangleOffsets.length);
mAllocOffsets.data(mFSM.mTriangleOffsets);
mScriptStrip.bindAllocation(mAllocOffsets, 4);
- mAllocOffsetsTex = mRS.allocationCreatePredefSized(
- RenderScript.ElementPredefined.USER_FLOAT,
- mFSM.mTriangleOffsetsTex.length);
+ mAllocOffsetsTex = mRS.allocationCreateSized(
+ Element.USER_FLOAT, mFSM.mTriangleOffsetsTex.length);
mAllocOffsetsTex.data(mFSM.mTriangleOffsetsTex);
mScriptStrip.bindAllocation(mAllocOffsetsTex, 5);
diff --git a/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java b/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java
index c8e9a1e..654d6cf 100644
--- a/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java
+++ b/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java
@@ -23,9 +23,11 @@ import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
+import android.util.Log;
+
import android.renderscript.RenderScript;
import android.renderscript.ProgramVertexAlloc;
-import android.util.Log;
+import android.renderscript.Element;
public class FountainRS {
@@ -65,10 +67,10 @@ public class FountainRS {
private void initRS() {
int partCount = 1024;
- mIntAlloc = mRS.allocationCreatePredefSized(RenderScript.ElementPredefined.USER_I32, 10);
- mPartAlloc = mRS.allocationCreatePredefSized(RenderScript.ElementPredefined.USER_I32, partCount * 3 * 3);
+ mIntAlloc = mRS.allocationCreateSized(Element.USER_I32, 10);
+ mPartAlloc = mRS.allocationCreateSized(Element.USER_I32, partCount * 3 * 3);
mPartAlloc.setName("PartBuffer");
- mVertAlloc = mRS.allocationCreatePredefSized(RenderScript.ElementPredefined.USER_I32, partCount * 5 + 1);
+ mVertAlloc = mRS.allocationCreateSized(Element.USER_I32, partCount * 5 + 1);
mRS.programFragmentStoreBegin(null, null);
mRS.programFragmentStoreBlendFunc(RenderScript.BlendSrcFunc.SRC_ALPHA, RenderScript.BlendDstFunc.ONE);
diff --git a/libs/rs/java/Grass/src/com/android/grass/rs/GrassRS.java b/libs/rs/java/Grass/src/com/android/grass/rs/GrassRS.java
index bb13051..f5737da 100644
--- a/libs/rs/java/Grass/src/com/android/grass/rs/GrassRS.java
+++ b/libs/rs/java/Grass/src/com/android/grass/rs/GrassRS.java
@@ -17,8 +17,6 @@
package com.android.grass.rs;
import android.content.res.Resources;
-import android.renderscript.RenderScript;
-import static android.renderscript.RenderScript.ElementPredefined.*;
import static android.renderscript.RenderScript.SamplerParam.*;
import static android.renderscript.RenderScript.SamplerValue.*;
import static android.renderscript.RenderScript.EnvMode.*;
@@ -26,6 +24,9 @@ import static android.renderscript.RenderScript.DepthFunc.*;
import static android.renderscript.RenderScript.BlendSrcFunc;
import static android.renderscript.RenderScript.BlendDstFunc;
+import android.renderscript.RenderScript;
+import android.renderscript.Element;
+
import java.util.TimeZone;
class GrassRS {
@@ -85,15 +86,15 @@ class GrassRS {
}
private void createScriptStructures() {
- mState = mRS.allocationCreatePredefSized(RenderScript.ElementPredefined.USER_I32, 1);
+ mState = mRS.allocationCreateSized(Element.USER_I32, 1);
mState.data(new int[1]);
}
private void loadSkyTextures() {
mSkyBufferIDs = new int[SKY_TEXTURES_COUNT];
mSkyTextures = new RenderScript.Allocation[SKY_TEXTURES_COUNT];
- mSkyTexturesIDs = mRS.allocationCreatePredefSized(
- USER_FLOAT, SKY_TEXTURES_COUNT);
+ mSkyTexturesIDs = mRS.allocationCreateSized(
+ Element.USER_FLOAT, SKY_TEXTURES_COUNT);
final RenderScript.Allocation[] textures = mSkyTextures;
textures[0] = loadTexture(R.drawable.night, "night");
@@ -115,7 +116,7 @@ class GrassRS {
private RenderScript.Allocation loadTexture(int id, String name) {
RenderScript.Allocation allocation = mRS.allocationCreateFromBitmapResource(mResources, id,
- RGB_565, false);
+ Element.RGB_565, false);
allocation.setName(name);
return allocation;
}
diff --git a/libs/rs/java/Rollo/res/raw/rollo.c b/libs/rs/java/Rollo/res/raw/rollo.c
index 8763a34..a527588 100644
--- a/libs/rs/java/Rollo/res/raw/rollo.c
+++ b/libs/rs/java/Rollo/res/raw/rollo.c
@@ -90,9 +90,6 @@ int main(void* con, int ft, int launchID)
float ty1 = ((y * 3.1f) - 5.f) * scale;
float ty2 = ty1 + scale * 1.8f;
bindTexture(NAMED_PF, 0, loadI32(1, index));
- //if (done && (index != selectedID)) {
- //color(0.4f, 0.4f, 0.4f, 1.0f);
- //}
drawQuad(tx1, ty1, tz1,
tx2, ty1, tz2,
tx2, ty2, tz2,
diff --git a/libs/rs/java/Rollo/src/com/android/rollo/RolloMesh.java b/libs/rs/java/Rollo/src/com/android/rollo/RolloMesh.java
deleted file mode 100644
index d7252fb..0000000
--- a/libs/rs/java/Rollo/src/com/android/rollo/RolloMesh.java
+++ /dev/null
@@ -1,90 +0,0 @@
- /*
- * Copyright (C) 2009 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 com.android.rollo;
-
-import java.io.Writer;
-import java.lang.Math;
-
-import android.renderscript.RenderScript;
-
-
-class RolloMesh {
- static public final float mCardHeight = 1.2f;
- static public final float mCardWidth = 1.8f;
- static public final float mTabHeight = 0.2f;
- static public final float mTabs = 3;
- static public final float mTabGap = 0.1f;
-
- static RenderScript.TriangleMesh createCard(RenderScript rs) {
- RenderScript.Element vtx = rs.elementGetPredefined(
- RenderScript.ElementPredefined.ST_XYZ_F32);
- RenderScript.Element idx = rs.elementGetPredefined(
- RenderScript.ElementPredefined.INDEX_16);
-
- float w = mCardWidth / 2;
- float h = mCardHeight;
- float z = 0;
-
- rs.triangleMeshBegin(vtx, idx);
- rs.triangleMeshAddVertex_XYZ_ST(-w, 0, z, 0, 0);
- rs.triangleMeshAddVertex_XYZ_ST(-w, h, z, 0, 1);
- rs.triangleMeshAddVertex_XYZ_ST( w, h, z, 1, 1);
- rs.triangleMeshAddVertex_XYZ_ST( w, 0, z, 1, 0);
- rs.triangleMeshAddTriangle(0,1,2);
- rs.triangleMeshAddTriangle(0,2,3);
- return rs.triangleMeshCreate();
- }
-
- static RenderScript.TriangleMesh createTab(RenderScript rs) {
- RenderScript.Element vtx = rs.elementGetPredefined(
- RenderScript.ElementPredefined.ST_XYZ_F32);
- RenderScript.Element idx = rs.elementGetPredefined(
- RenderScript.ElementPredefined.INDEX_16);
-
-
- float tabSlope = 0.1f;
- float num = 0;
-
- float w = (mCardWidth - ((mTabs - 1) * mTabGap)) / mTabs;
- float w1 = -(mCardWidth / 2) + ((w + mTabGap) * num);
- float w2 = w1 + (w * tabSlope);
- float w3 = w1 + w - (w * tabSlope);
- float w4 = w1 + w;
- float h1 = mCardHeight;
- float h2 = h1 + mTabHeight;
- float z = 0;
-
- float stScale = w / mTabHeight / 2;
- float stScale2 = stScale * (tabSlope / w);
-
-
- rs.triangleMeshBegin(vtx, idx);
- rs.triangleMeshAddVertex_XYZ_ST(w1, h1, z, -stScale, 0);
- rs.triangleMeshAddVertex_XYZ_ST(w2, h2, z, -stScale2, 1);
- rs.triangleMeshAddVertex_XYZ_ST(w3, h2, z, stScale2, 1);
- rs.triangleMeshAddVertex_XYZ_ST(w4, h1, z, stScale, 0);
- rs.triangleMeshAddTriangle(0,1,2);
- rs.triangleMeshAddTriangle(0,2,3);
- return rs.triangleMeshCreate();
- }
-
-
-
-}
-
-
diff --git a/libs/rs/java/Rollo/src/com/android/rollo/RolloRS.java b/libs/rs/java/Rollo/src/com/android/rollo/RolloRS.java
index 039d4e9..7f9727c 100644
--- a/libs/rs/java/Rollo/src/com/android/rollo/RolloRS.java
+++ b/libs/rs/java/Rollo/src/com/android/rollo/RolloRS.java
@@ -20,9 +20,8 @@ import java.io.Writer;
import android.renderscript.RenderScript;
import android.renderscript.ProgramVertexAlloc;
+import android.renderscript.Element;
-import android.content.Context;
-import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
@@ -30,8 +29,9 @@ import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.Typeface;
-import android.os.Handler;
-import android.os.Message;
+
+import android.content.Context;
+import android.content.res.Resources;
import android.util.Log;
public class RolloRS {
@@ -190,8 +190,8 @@ public class RolloRS {
mRS.contextBindProgramVertex(mPV);
mAllocScratchBuf = new int[32];
- mAllocScratch = mRS.allocationCreatePredefSized(
- RenderScript.ElementPredefined.USER_I32, mAllocScratchBuf.length);
+ mAllocScratch = mRS.allocationCreateSized(
+ Element.USER_I32, mAllocScratchBuf.length);
mAllocScratch.data(mAllocScratchBuf);
Log.e("rs", "Done loading named");
@@ -201,18 +201,15 @@ public class RolloRS {
{
mIcons = new RenderScript.Allocation[29];
mAllocIconIDBuf = new int[mIcons.length];
- mAllocIconID = mRS.allocationCreatePredefSized(
- RenderScript.ElementPredefined.USER_I32, mAllocIconIDBuf.length);
+ mAllocIconID = mRS.allocationCreateSized(
+ Element.USER_I32, mAllocIconIDBuf.length);
mLabels = new RenderScript.Allocation[29];
mAllocLabelIDBuf = new int[mLabels.length];
- mAllocLabelID = mRS.allocationCreatePredefSized(
- RenderScript.ElementPredefined.USER_I32, mLabels.length);
+ mAllocLabelID = mRS.allocationCreateSized(
+ Element.USER_I32, mLabels.length);
- RenderScript.ElementPredefined ie565 =
- RenderScript.ElementPredefined.RGB_565;
- RenderScript.ElementPredefined ie8888 =
- RenderScript.ElementPredefined.RGBA_8888;
+ Element ie8888 = Element.RGBA_8888;
mIcons[0] = mRS.allocationCreateFromBitmapResource(mRes, R.raw.browser, ie8888, true);
mIcons[1] = mRS.allocationCreateFromBitmapResource(mRes, R.raw.market, ie8888, true);
@@ -310,7 +307,7 @@ public class RolloRS {
p.setTextSize(20);
p.setColor(0xffffffff);
c.drawText(t, 2, 26, p);
- return mRS.allocationCreateFromBitmap(b, RenderScript.ElementPredefined.RGBA_8888, true);
+ return mRS.allocationCreateFromBitmap(b, Element.RGBA_8888, true);
}
@@ -323,8 +320,8 @@ public class RolloRS {
mScript = mRS.scriptCCreate();
mAllocStateBuf = new int[] {0, 0, 0, 8, 0, 0, -1, 0, mAllocIconIDBuf.length, 0, 0};
- mAllocState = mRS.allocationCreatePredefSized(
- RenderScript.ElementPredefined.USER_I32, mAllocStateBuf.length);
+ mAllocState = mRS.allocationCreateSized(
+ Element.USER_I32, mAllocStateBuf.length);
mScript.bindAllocation(mAllocState, 0);
mScript.bindAllocation(mAllocIconID, 1);
mScript.bindAllocation(mAllocScratch, 2);