From b8c5a84e7c23746a3fc26013e0880d3d95ca6588 Mon Sep 17 00:00:00 2001 From: Jason Sams Date: Fri, 31 Jul 2009 20:40:47 -0700 Subject: [PATCH] Split RenderScript Type and Allocation into seperate classes. --- .../java/android/renderscript/Allocation.java | 175 ++++++++++++++++ .../java/android/renderscript/Dimension.java | 35 ++++ .../renderscript/ProgramVertexAlloc.java | 6 +- .../android/renderscript/RenderScript.java | 194 +----------------- graphics/java/android/renderscript/Type.java | 68 ++++++ .../Film/src/com/android/film/FilmRS.java | 53 ++--- .../src/com/android/fountain/FountainRS.java | 13 +- .../src/com/android/grass/rs/GrassRS.java | 29 +-- .../Rollo/src/com/android/rollo/RolloRS.java | 87 ++++---- 9 files changed, 381 insertions(+), 279 deletions(-) create mode 100644 graphics/java/android/renderscript/Allocation.java create mode 100644 graphics/java/android/renderscript/Dimension.java create mode 100644 graphics/java/android/renderscript/Type.java diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java new file mode 100644 index 0000000000000..13273280fb9cf --- /dev/null +++ b/graphics/java/android/renderscript/Allocation.java @@ -0,0 +1,175 @@ +/* + * Copyright (C) 2008 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 android.renderscript; + + +import java.io.IOException; +import java.io.InputStream; + +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.Bundle; +import android.renderscript.Type; +import android.util.Config; +import android.util.Log; + +/** + * @hide + * + **/ +public class Allocation extends BaseObj { + Allocation(int id, RenderScript rs) { + super(rs); + mID = id; + } + + public void uploadToTexture(int baseMipLevel) { + mRS.nAllocationUploadToTexture(mID, baseMipLevel); + } + + public void destroy() { + mRS.nAllocationDestroy(mID); + mID = 0; + } + + public void data(int[] d) { + mRS.nAllocationData(mID, d); + } + + public void data(float[] d) { + mRS.nAllocationData(mID, d); + } + + public void subData1D(int off, int count, int[] d) { + mRS.nAllocationSubData1D(mID, off, count, d); + } + + public void subData1D(int off, int count, float[] d) { + mRS.nAllocationSubData1D(mID, off, count, d); + } + + public void subData2D(int xoff, int yoff, int w, int h, int[] d) { + mRS.nAllocationSubData2D(mID, xoff, yoff, w, h, d); + } + + public void subData2D(int xoff, int yoff, int w, int h, float[] d) { + mRS.nAllocationSubData2D(mID, xoff, yoff, w, h, d); + } + + public class Adapter1D extends BaseObj { + Adapter1D(int id, RenderScript rs) { + super(rs); + mID = id; + } + + public void destroy() { + mRS.nAdapter1DDestroy(mID); + mID = 0; + } + + public void setConstraint(Dimension dim, int value) { + mRS.nAdapter1DSetConstraint(mID, dim.mID, value); + } + + public void data(int[] d) { + mRS.nAdapter1DData(mID, d); + } + + public void subData(int off, int count, int[] d) { + mRS.nAdapter1DSubData(mID, off, count, d); + } + + public void data(float[] d) { + mRS.nAdapter1DData(mID, d); + } + + public void subData(int off, int count, float[] d) { + mRS.nAdapter1DSubData(mID, off, count, d); + } + } + + public Adapter1D createAdapter1D() { + int id = mRS.nAdapter1DCreate(); + if (id != 0) { + mRS.nAdapter1DBindAllocation(id, mID); + } + return new Adapter1D(id, mRS); + } + + + + // creation + + private static BitmapFactory.Options mBitmapOptions = new BitmapFactory.Options(); + static { + mBitmapOptions.inScaled = false; + } + + static public Allocation createTyped(RenderScript rs, Type type) { + int id = rs.nAllocationCreateTyped(type.mID); + return new Allocation(id, rs); + } + + static public Allocation createSized(RenderScript rs, Element e, int count) { + int id; + if(e.mIsPredefined) { + id = rs.nAllocationCreatePredefSized(e.mPredefinedID, count); + } else { + id = rs.nAllocationCreateSized(e.mID, count); + } + return new Allocation(id, rs); + } + + static public Allocation createFromBitmap(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips) + throws IllegalArgumentException { + if(!dstFmt.mIsPredefined) { + throw new IllegalStateException("Attempting to allocate a bitmap with a non-static element."); + } + + int id = rs.nAllocationCreateFromBitmap(dstFmt.mPredefinedID, genMips, b); + return new Allocation(id, rs); + } + + static public Allocation createFromBitmapBoxed(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips) + throws IllegalArgumentException { + if(!dstFmt.mIsPredefined) { + throw new IllegalStateException("Attempting to allocate a bitmap with a non-static element."); + } + + int id = rs.nAllocationCreateFromBitmapBoxed(dstFmt.mPredefinedID, genMips, b); + return new Allocation(id, rs); + } + + static public Allocation createFromBitmapResource(RenderScript rs, Resources res, int id, Element dstFmt, boolean genMips) + throws IllegalArgumentException { + + Bitmap b = BitmapFactory.decodeResource(res, id, mBitmapOptions); + return createFromBitmap(rs, b, dstFmt, genMips); + } + + static public Allocation createFromBitmapResourceBoxed(RenderScript rs, Resources res, int id, Element dstFmt, boolean genMips) + throws IllegalArgumentException { + + Bitmap b = BitmapFactory.decodeResource(res, id, mBitmapOptions); + return createFromBitmapBoxed(rs, b, dstFmt, genMips); + } + + +} + + diff --git a/graphics/java/android/renderscript/Dimension.java b/graphics/java/android/renderscript/Dimension.java new file mode 100644 index 0000000000000..f29057d4cd04c --- /dev/null +++ b/graphics/java/android/renderscript/Dimension.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2008 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 android.renderscript; + +/** + * @hide + **/ +public enum Dimension { + X (0), + Y (1), + Z (2), + LOD (3), + FACE (4), + ARRAY_0 (100); + + int mID; + Dimension(int id) { + mID = id; + } +} + diff --git a/graphics/java/android/renderscript/ProgramVertexAlloc.java b/graphics/java/android/renderscript/ProgramVertexAlloc.java index 424e0ad33b161..37b037c3a4ff7 100644 --- a/graphics/java/android/renderscript/ProgramVertexAlloc.java +++ b/graphics/java/android/renderscript/ProgramVertexAlloc.java @@ -17,6 +17,8 @@ package android.renderscript; import java.lang.Math; + +import android.renderscript.Element; import android.util.Log; @@ -33,14 +35,14 @@ public class ProgramVertexAlloc { Matrix mProjection; Matrix mTexture; - public RenderScript.Allocation mAlloc; + public Allocation mAlloc; public ProgramVertexAlloc(RenderScript rs) { mModel = new Matrix(); mProjection = new Matrix(); mTexture = new Matrix(); - mAlloc = rs.allocationCreateSized(Element.USER_FLOAT, 48); + mAlloc = Allocation.createSized(rs, Element.USER_FLOAT, 48); mAlloc.subData1D(MODELVIEW_OFFSET, 16, mModel.mMat); mAlloc.subData1D(PROJECTION_OFFSET, 16, mProjection.mMat); mAlloc.subData1D(TEXTURE_OFFSET, 16, mTexture.mMat); diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java index 3d4f33335c646..dc87b6a62acb2 100644 --- a/graphics/java/android/renderscript/RenderScript.java +++ b/graphics/java/android/renderscript/RenderScript.java @@ -20,15 +20,11 @@ import java.io.IOException; import java.io.InputStream; import android.content.res.Resources; -import android.os.Bundle; +import android.graphics.Bitmap; import android.util.Config; import android.util.Log; import android.view.Surface; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.graphics.Color; - /** * @hide @@ -48,7 +44,6 @@ public class RenderScript { private static boolean sInitialized; native private static void _nInit(); - private static BitmapFactory.Options mBitmapOptions = new BitmapFactory.Options(); static { sInitialized = false; @@ -59,7 +54,6 @@ public class RenderScript { } catch (UnsatisfiedLinkError e) { Log.d(LOG_TAG, "RenderScript JNI library not found!"); } - mBitmapOptions.inScaled = false; } native int nDeviceCreate(); @@ -206,6 +200,11 @@ public class RenderScript { return mElementBuilder; } + Type.Builder mTypeBuilder = new Type.Builder(this); + public Type.Builder typeBuilderCreate(Element e) throws IllegalStateException { + mTypeBuilder.begin(e); + return mTypeBuilder; + } @@ -294,187 +293,6 @@ public class RenderScript { } } - ////////////////////////////////////////////////////////////////////////////////// - // Type - - public enum Dimension { - X (0), - Y (1), - Z (2), - LOD (3), - FACE (4), - ARRAY_0 (100); - - int mID; - Dimension(int id) { - mID = id; - } - } - - public class Type extends BaseObj { - Type(int id) { - super(RenderScript.this); - mID = id; - } - - public void destroy() { - nTypeDestroy(mID); - mID = 0; - } - } - - public void typeBegin(Element e) { - nTypeBegin(e.mID); - } - - public void typeAdd(Dimension d, int value) { - nTypeAdd(d.mID, value); - } - - public Type typeCreate() { - int id = nTypeCreate(); - return new Type(id); - } - - - ////////////////////////////////////////////////////////////////////////////////// - // Allocation - - public class Allocation extends BaseObj { - Allocation(int id) { - super(RenderScript.this); - mID = id; - } - - public void uploadToTexture(int baseMipLevel) { - nAllocationUploadToTexture(mID, baseMipLevel); - } - - public void destroy() { - nAllocationDestroy(mID); - mID = 0; - } - - public void data(int[] d) { - nAllocationData(mID, d); - } - - public void data(float[] d) { - nAllocationData(mID, d); - } - - public void subData1D(int off, int count, int[] d) { - nAllocationSubData1D(mID, off, count, d); - } - - public void subData1D(int off, int count, float[] d) { - nAllocationSubData1D(mID, off, count, d); - } - - public void subData2D(int xoff, int yoff, int w, int h, int[] d) { - nAllocationSubData2D(mID, xoff, yoff, w, h, d); - } - - public void subData2D(int xoff, int yoff, int w, int h, float[] d) { - nAllocationSubData2D(mID, xoff, yoff, w, h, d); - } - } - - public Allocation allocationCreateTyped(Type type) { - int id = nAllocationCreateTyped(type.mID); - return new Allocation(id); - } - - public Allocation allocationCreateSized(Element e, int count) { - int id; - if(e.mIsPredefined) { - id = nAllocationCreatePredefSized(e.mPredefinedID, count); - } else { - id = nAllocationCreateSized(e.mID, count); - } - return new Allocation(id); - } - - public Allocation allocationCreateFromBitmap(Bitmap b, Element dstFmt, boolean genMips) - throws IllegalArgumentException { - if(!dstFmt.mIsPredefined) { - throw new IllegalStateException("Attempting to allocate a bitmap with a non-static element."); - } - - int id = nAllocationCreateFromBitmap(dstFmt.mPredefinedID, genMips, b); - return new Allocation(id); - } - - public Allocation allocationCreateFromBitmapBoxed(Bitmap b, Element dstFmt, boolean genMips) - throws IllegalArgumentException { - if(!dstFmt.mIsPredefined) { - throw new IllegalStateException("Attempting to allocate a bitmap with a non-static element."); - } - - int id = nAllocationCreateFromBitmapBoxed(dstFmt.mPredefinedID, genMips, b); - return new Allocation(id); - } - - public Allocation allocationCreateFromBitmapResource(Resources res, int id, Element dstFmt, boolean genMips) - throws IllegalArgumentException { - - Bitmap b = BitmapFactory.decodeResource(res, id, mBitmapOptions); - return allocationCreateFromBitmap(b, dstFmt, genMips); - } - - public Allocation allocationCreateFromBitmapResourceBoxed(Resources res, int id, Element dstFmt, boolean genMips) - throws IllegalArgumentException { - - Bitmap b = BitmapFactory.decodeResource(res, id, mBitmapOptions); - return allocationCreateFromBitmapBoxed(b, dstFmt, genMips); - } - - - ////////////////////////////////////////////////////////////////////////////////// - // Adapter1D - - public class Adapter1D extends BaseObj { - Adapter1D(int id) { - super(RenderScript.this); - mID = id; - } - - public void destroy() { - nAdapter1DDestroy(mID); - mID = 0; - } - - public void bindAllocation(Allocation a) { - nAdapter1DBindAllocation(mID, a.mID); - } - - public void setConstraint(Dimension dim, int value) { - nAdapter1DSetConstraint(mID, dim.mID, value); - } - - public void data(int[] d) { - nAdapter1DData(mID, d); - } - - public void subData(int off, int count, int[] d) { - nAdapter1DSubData(mID, off, count, d); - } - - public void data(float[] d) { - nAdapter1DData(mID, d); - } - - public void subData(int off, int count, float[] d) { - nAdapter1DSubData(mID, off, count, d); - } - } - - public Adapter1D adapter1DCreate() { - int id = nAdapter1DCreate(); - return new Adapter1D(id); - } - - ////////////////////////////////////////////////////////////////////////////////// // Triangle Mesh diff --git a/graphics/java/android/renderscript/Type.java b/graphics/java/android/renderscript/Type.java new file mode 100644 index 0000000000000..86932c4e95c33 --- /dev/null +++ b/graphics/java/android/renderscript/Type.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2008 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 android.renderscript; + + +import java.io.IOException; +import java.io.InputStream; + +import android.content.res.Resources; +import android.os.Bundle; +import android.util.Config; +import android.util.Log; + +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; + +/** + * @hide + * + **/ +public class Type extends BaseObj { + Type(int id, RenderScript rs) { + super(rs); + mID = id; + } + + public void destroy() { + mRS.nTypeDestroy(mID); + mID = 0; + } + + public static class Builder { + RenderScript mRS; + boolean mActive = true; + + Builder(RenderScript rs) { + mRS = rs; + } + + public void begin(Element e) { + mRS.nTypeBegin(e.mID); + } + + public void add(Dimension d, int value) { + mRS.nTypeAdd(d.mID, value); + } + + public Type create() { + int id = mRS.nTypeCreate(); + return new Type(id, mRS); + } + } + +} 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 0e5b1bd28e585..777a7cf18e206 100644 --- a/libs/rs/java/Film/src/com/android/film/FilmRS.java +++ b/libs/rs/java/Film/src/com/android/film/FilmRS.java @@ -27,6 +27,7 @@ import android.renderscript.Matrix; import android.renderscript.ProgramVertexAlloc; import android.renderscript.RenderScript; import android.renderscript.Element; +import android.renderscript.Allocation; public class FilmRS { private final int POS_TRANSLATE = 0; @@ -77,13 +78,13 @@ public class FilmRS { private RenderScript.ProgramVertex mPVImages; private ProgramVertexAlloc mPVA; - private RenderScript.Allocation mImages[]; - private RenderScript.Allocation mAllocIDs; - private RenderScript.Allocation mAllocPos; - private RenderScript.Allocation mAllocState; - private RenderScript.Allocation mAllocPV; - private RenderScript.Allocation mAllocOffsetsTex; - private RenderScript.Allocation mAllocOffsets; + private Allocation mImages[]; + private Allocation mAllocIDs; + private Allocation mAllocPos; + private Allocation mAllocState; + private Allocation mAllocPV; + private Allocation mAllocOffsetsTex; + private Allocation mAllocOffsets; private RenderScript.TriangleMesh mMesh; private RenderScript.Light mLight; @@ -155,24 +156,24 @@ public class FilmRS { private void loadImages() { mBufferIDs = new int[13]; - mImages = new RenderScript.Allocation[13]; - mAllocIDs = mRS.allocationCreateSized( + mImages = new Allocation[13]; + mAllocIDs = Allocation.createSized(mRS, 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); - mImages[3] = mRS.allocationCreateFromBitmapResourceBoxed(mRes, R.drawable.p04, ie, true); - mImages[4] = mRS.allocationCreateFromBitmapResourceBoxed(mRes, R.drawable.p05, ie, true); - mImages[5] = mRS.allocationCreateFromBitmapResourceBoxed(mRes, R.drawable.p06, ie, true); - mImages[6] = mRS.allocationCreateFromBitmapResourceBoxed(mRes, R.drawable.p07, ie, true); - mImages[7] = mRS.allocationCreateFromBitmapResourceBoxed(mRes, R.drawable.p08, ie, true); - mImages[8] = mRS.allocationCreateFromBitmapResourceBoxed(mRes, R.drawable.p09, ie, true); - mImages[9] = mRS.allocationCreateFromBitmapResourceBoxed(mRes, R.drawable.p10, ie, true); - mImages[10] = mRS.allocationCreateFromBitmapResourceBoxed(mRes, R.drawable.p11, ie, true); - mImages[11] = mRS.allocationCreateFromBitmapResourceBoxed(mRes, R.drawable.p12, ie, true); - mImages[12] = mRS.allocationCreateFromBitmapResourceBoxed(mRes, R.drawable.p13, ie, true); + mImages[0] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p01, ie, true); + mImages[1] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p02, ie, true); + mImages[2] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p03, ie, true); + mImages[3] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p04, ie, true); + mImages[4] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p05, ie, true); + mImages[5] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p06, ie, true); + mImages[6] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p07, ie, true); + mImages[7] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p08, ie, true); + mImages[8] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p09, ie, true); + mImages[9] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p10, ie, true); + mImages[10] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p11, ie, true); + mImages[11] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p12, ie, true); + mImages[12] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p13, ie, true); for(int ct=0; ct < mImages.length; ct++) { mImages[ct].uploadToTexture(1); @@ -184,7 +185,7 @@ public class FilmRS { private void initState() { mBufferState = new int[10]; - mAllocState = mRS.allocationCreateSized( + mAllocState = Allocation.createSized(mRS, Element.USER_FLOAT, mBufferState.length); mBufferState[STATE_TRIANGLE_OFFSET_COUNT] = mFSM.mTriangleOffsetsCount; @@ -215,7 +216,7 @@ public class FilmRS { mRS.scriptCSetRoot(true); mScriptStrip = mRS.scriptCCreate(); - mAllocPos = mRS.allocationCreateSized( + mAllocPos = Allocation.createSized(mRS, Element.USER_FLOAT, mBufferPos.length); loadImages(); @@ -233,12 +234,12 @@ public class FilmRS { mScriptStrip.bindAllocation(mPVA.mAlloc, 3); - mAllocOffsets = mRS.allocationCreateSized( + mAllocOffsets = Allocation.createSized(mRS, Element.USER_I32, mFSM.mTriangleOffsets.length); mAllocOffsets.data(mFSM.mTriangleOffsets); mScriptStrip.bindAllocation(mAllocOffsets, 4); - mAllocOffsetsTex = mRS.allocationCreateSized( + mAllocOffsetsTex = Allocation.createSized(mRS, 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 654d6cf12ab05..7123bf765be34 100644 --- a/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java +++ b/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java @@ -28,6 +28,7 @@ import android.util.Log; import android.renderscript.RenderScript; import android.renderscript.ProgramVertexAlloc; import android.renderscript.Element; +import android.renderscript.Allocation; public class FountainRS { @@ -53,9 +54,9 @@ public class FountainRS { private Resources mRes; private RenderScript mRS; - private RenderScript.Allocation mIntAlloc; - private RenderScript.Allocation mPartAlloc; - private RenderScript.Allocation mVertAlloc; + private Allocation mIntAlloc; + private Allocation mPartAlloc; + private Allocation mVertAlloc; private RenderScript.Script mScript; private RenderScript.ProgramFragmentStore mPFS; private RenderScript.ProgramFragment mPF; @@ -67,10 +68,10 @@ public class FountainRS { private void initRS() { int partCount = 1024; - mIntAlloc = mRS.allocationCreateSized(Element.USER_I32, 10); - mPartAlloc = mRS.allocationCreateSized(Element.USER_I32, partCount * 3 * 3); + mIntAlloc = Allocation.createSized(mRS, Element.USER_I32, 10); + mPartAlloc = Allocation.createSized(mRS, Element.USER_I32, partCount * 3 * 3); mPartAlloc.setName("PartBuffer"); - mVertAlloc = mRS.allocationCreateSized(Element.USER_I32, partCount * 5 + 1); + mVertAlloc = Allocation.createSized(mRS, 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 f5737da3a1c24..70cb012496668 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 @@ -26,6 +26,7 @@ import static android.renderscript.RenderScript.BlendDstFunc; import android.renderscript.RenderScript; import android.renderscript.Element; +import android.renderscript.Allocation; import java.util.TimeZone; @@ -47,13 +48,13 @@ class GrassRS { private RenderScript.ProgramFragmentStore mPfsBackground; @SuppressWarnings({"FieldCanBeLocal"}) - private RenderScript.Allocation mSkyTexturesIDs; + private Allocation mSkyTexturesIDs; @SuppressWarnings({"FieldCanBeLocal"}) - private RenderScript.Allocation[] mSkyTextures; + private Allocation[] mSkyTextures; @SuppressWarnings({"FieldCanBeLocal"}) private int[] mSkyBufferIDs; @SuppressWarnings({"FieldCanBeLocal"}) - private RenderScript.Allocation mState; + private Allocation mState; public GrassRS() { } @@ -69,7 +70,7 @@ class GrassRS { createProgramFragmentStore(); createProgramFragment(); createScriptStructures(); - + mRS.scriptCBegin(); mRS.scriptCSetClearColor(0.0f, 0.0f, 0.0f, 1.0f); mRS.scriptCSetScript(mResources, R.raw.grass); @@ -78,25 +79,25 @@ class GrassRS { mScript = mRS.scriptCCreate(); - loadSkyTextures(); + loadSkyTextures(); mScript.bindAllocation(mState, RSID_STATE); mScript.bindAllocation(mSkyTexturesIDs, RSID_SKY_TEXTURES); - mRS.contextBindRootScript(mScript); + mRS.contextBindRootScript(mScript); } private void createScriptStructures() { - mState = mRS.allocationCreateSized(Element.USER_I32, 1); + mState = Allocation.createSized(mRS, 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.allocationCreateSized( - Element.USER_FLOAT, SKY_TEXTURES_COUNT); + mSkyTextures = new Allocation[SKY_TEXTURES_COUNT]; + mSkyTexturesIDs = Allocation.createSized( + mRS, Element.USER_FLOAT, SKY_TEXTURES_COUNT); - final RenderScript.Allocation[] textures = mSkyTextures; + final Allocation[] textures = mSkyTextures; textures[0] = loadTexture(R.drawable.night, "night"); textures[1] = loadTexture(R.drawable.sunrise, "sunrise"); textures[2] = loadTexture(R.drawable.sky, "sky"); @@ -106,7 +107,7 @@ class GrassRS { final int count = textures.length; for (int i = 0; i < count; i++) { - final RenderScript.Allocation texture = textures[i]; + final Allocation texture = textures[i]; texture.uploadToTexture(0); bufferIds[i] = texture.getID(); } @@ -114,8 +115,8 @@ class GrassRS { mSkyTexturesIDs.data(bufferIds); } - private RenderScript.Allocation loadTexture(int id, String name) { - RenderScript.Allocation allocation = mRS.allocationCreateFromBitmapResource(mResources, id, + private Allocation loadTexture(int id, String name) { + Allocation allocation = Allocation.createFromBitmapResource(mRS, mResources, id, Element.RGB_565, false); allocation.setName(name); return allocation; 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 7f9727c0ef174..cb3dd51061c53 100644 --- a/libs/rs/java/Rollo/src/com/android/rollo/RolloRS.java +++ b/libs/rs/java/Rollo/src/com/android/rollo/RolloRS.java @@ -21,6 +21,7 @@ import java.io.Writer; import android.renderscript.RenderScript; import android.renderscript.ProgramVertexAlloc; import android.renderscript.Element; +import android.renderscript.Allocation; import android.graphics.Bitmap; import android.graphics.BitmapFactory; @@ -100,20 +101,20 @@ public class RolloRS { private ProgramVertexAlloc mPVAlloc; private RenderScript.ProgramVertex mPVOrtho; private ProgramVertexAlloc mPVOrthoAlloc; - private RenderScript.Allocation[] mIcons; - private RenderScript.Allocation[] mLabels; + private Allocation[] mIcons; + private Allocation[] mLabels; private int[] mAllocStateBuf; - private RenderScript.Allocation mAllocState; + private Allocation mAllocState; private int[] mAllocIconIDBuf; - private RenderScript.Allocation mAllocIconID; + private Allocation mAllocIconID; private int[] mAllocLabelIDBuf; - private RenderScript.Allocation mAllocLabelID; + private Allocation mAllocLabelID; private int[] mAllocScratchBuf; - private RenderScript.Allocation mAllocScratch; + private Allocation mAllocScratch; private void initNamed() { mRS.samplerBegin(); @@ -190,7 +191,7 @@ public class RolloRS { mRS.contextBindProgramVertex(mPV); mAllocScratchBuf = new int[32]; - mAllocScratch = mRS.allocationCreateSized( + mAllocScratch = Allocation.createSized(mRS, Element.USER_I32, mAllocScratchBuf.length); mAllocScratch.data(mAllocScratchBuf); @@ -199,37 +200,37 @@ public class RolloRS { { - mIcons = new RenderScript.Allocation[29]; + mIcons = new Allocation[29]; mAllocIconIDBuf = new int[mIcons.length]; - mAllocIconID = mRS.allocationCreateSized( + mAllocIconID = Allocation.createSized(mRS, Element.USER_I32, mAllocIconIDBuf.length); - mLabels = new RenderScript.Allocation[29]; + mLabels = new Allocation[29]; mAllocLabelIDBuf = new int[mLabels.length]; - mAllocLabelID = mRS.allocationCreateSized( + mAllocLabelID = Allocation.createSized(mRS, Element.USER_I32, mLabels.length); 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); - mIcons[2] = mRS.allocationCreateFromBitmapResource(mRes, R.raw.photos, ie8888, true); - mIcons[3] = mRS.allocationCreateFromBitmapResource(mRes, R.raw.settings, ie8888, true); - mIcons[4] = mRS.allocationCreateFromBitmapResource(mRes, R.raw.calendar, ie8888, true); - mIcons[5] = mRS.allocationCreateFromBitmapResource(mRes, R.raw.g1155, ie8888, true); - mIcons[6] = mRS.allocationCreateFromBitmapResource(mRes, R.raw.g2140, ie8888, true); - mIcons[7] = mRS.allocationCreateFromBitmapResource(mRes, R.raw.maps, ie8888, true); - mIcons[8] = mRS.allocationCreateFromBitmapResource(mRes, R.raw.path431, ie8888, true); - mIcons[9] = mRS.allocationCreateFromBitmapResource(mRes, R.raw.path676, ie8888, true); - mIcons[10] = mRS.allocationCreateFromBitmapResource(mRes, R.raw.path754, ie8888, true); - mIcons[11] = mRS.allocationCreateFromBitmapResource(mRes, R.raw.path815, ie8888, true); - mIcons[12] = mRS.allocationCreateFromBitmapResource(mRes, R.raw.path1920, ie8888, true); - mIcons[13] = mRS.allocationCreateFromBitmapResource(mRes, R.raw.path1927, ie8888, true); - mIcons[14] = mRS.allocationCreateFromBitmapResource(mRes, R.raw.path3099, ie8888, true); - mIcons[15] = mRS.allocationCreateFromBitmapResource(mRes, R.raw.path3950, ie8888, true); - mIcons[16] = mRS.allocationCreateFromBitmapResource(mRes, R.raw.path4481, ie8888, true); - mIcons[17] = mRS.allocationCreateFromBitmapResource(mRes, R.raw.path5168, ie8888, true); - mIcons[18] = mRS.allocationCreateFromBitmapResource(mRes, R.raw.polygon2408, ie8888, true); + mIcons[0] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.browser, ie8888, true); + mIcons[1] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.market, ie8888, true); + mIcons[2] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.photos, ie8888, true); + mIcons[3] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.settings, ie8888, true); + mIcons[4] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.calendar, ie8888, true); + mIcons[5] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.g1155, ie8888, true); + mIcons[6] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.g2140, ie8888, true); + mIcons[7] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.maps, ie8888, true); + mIcons[8] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.path431, ie8888, true); + mIcons[9] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.path676, ie8888, true); + mIcons[10] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.path754, ie8888, true); + mIcons[11] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.path815, ie8888, true); + mIcons[12] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.path1920, ie8888, true); + mIcons[13] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.path1927, ie8888, true); + mIcons[14] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.path3099, ie8888, true); + mIcons[15] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.path3950, ie8888, true); + mIcons[16] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.path4481, ie8888, true); + mIcons[17] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.path5168, ie8888, true); + mIcons[18] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.polygon2408, ie8888, true); mLabels[0] = makeTextBitmap("browser"); mLabels[1] = makeTextBitmap("market"); @@ -274,16 +275,16 @@ public class RolloRS { mLabels[28] = mLabels[9]; /* - mIcons[19] = mRS.allocationCreateFromBitmapResource(mRes, R.raw.solitaire, ie8888, true); - mIcons[20] = mRS.allocationCreateFromBitmapResource(mRes, R.raw.sudoku, ie8888, true); - mIcons[21] = mRS.allocationCreateFromBitmapResource(mRes, R.raw.taptaprevenge, ie8888, true); - mIcons[22] = mRS.allocationCreateFromBitmapResource(mRes, R.raw.tetris, ie8888, true); - mIcons[23] = mRS.allocationCreateFromBitmapResource(mRes, R.raw.tictactoe, ie8888, true); - mIcons[24] = mRS.allocationCreateFromBitmapResource(mRes, R.raw.tweetie, ie8888, true); - mIcons[25] = mRS.allocationCreateFromBitmapResource(mRes, R.raw.urbanspoon, ie8888, true); - mIcons[26] = mRS.allocationCreateFromBitmapResource(mRes, R.raw.waterslide_extreme, ie8888, true); - mIcons[27] = mRS.allocationCreateFromBitmapResource(mRes, R.raw.weather_channel, ie8888, true); - mIcons[28] = mRS.allocationCreateFromBitmapResource(mRes, R.raw.zippo, ie8888, true); + mIcons[19] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.solitaire, ie8888, true); + mIcons[20] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.sudoku, ie8888, true); + mIcons[21] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.taptaprevenge, ie8888, true); + mIcons[22] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.tetris, ie8888, true); + mIcons[23] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.tictactoe, ie8888, true); + mIcons[24] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.tweetie, ie8888, true); + mIcons[25] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.urbanspoon, ie8888, true); + mIcons[26] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.waterslide_extreme, ie8888, true); + mIcons[27] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.weather_channel, ie8888, true); + mIcons[28] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.zippo, ie8888, true); */ @@ -299,7 +300,7 @@ public class RolloRS { } - RenderScript.Allocation makeTextBitmap(String t) { + Allocation makeTextBitmap(String t) { Bitmap b = Bitmap.createBitmap(128, 32, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(b); Paint p = new Paint(); @@ -307,7 +308,7 @@ public class RolloRS { p.setTextSize(20); p.setColor(0xffffffff); c.drawText(t, 2, 26, p); - return mRS.allocationCreateFromBitmap(b, Element.RGBA_8888, true); + return Allocation.createFromBitmap(mRS, b, Element.RGBA_8888, true); } @@ -320,7 +321,7 @@ public class RolloRS { mScript = mRS.scriptCCreate(); mAllocStateBuf = new int[] {0, 0, 0, 8, 0, 0, -1, 0, mAllocIconIDBuf.length, 0, 0}; - mAllocState = mRS.allocationCreateSized( + mAllocState = Allocation.createSized(mRS, Element.USER_I32, mAllocStateBuf.length); mScript.bindAllocation(mAllocState, 0); mScript.bindAllocation(mAllocIconID, 1);