diff options
author | Jason Sams <rjsams@android.com> | 2009-09-21 19:41:04 -0700 |
---|---|---|
committer | Jason Sams <rjsams@android.com> | 2009-09-21 19:41:04 -0700 |
commit | 768bc02d815a94ad29146f1ed60c847d1af118cc (patch) | |
tree | 1e7d9331f53bf4ef0ea3fdfbe7e6ff2e5c8940da /graphics/java/android/renderscript/Type.java | |
parent | 88a83d3f108dcf01443b241439e14eedbd9615f5 (diff) | |
download | frameworks_base-768bc02d815a94ad29146f1ed60c847d1af118cc.zip frameworks_base-768bc02d815a94ad29146f1ed60c847d1af118cc.tar.gz frameworks_base-768bc02d815a94ad29146f1ed60c847d1af118cc.tar.bz2 |
Implement more type checks on Allocations.
Add tracking for allocations created using the "sized" helper.
Add more param validation for data upload calls.
Diffstat (limited to 'graphics/java/android/renderscript/Type.java')
-rw-r--r-- | graphics/java/android/renderscript/Type.java | 86 |
1 files changed, 80 insertions, 6 deletions
diff --git a/graphics/java/android/renderscript/Type.java b/graphics/java/android/renderscript/Type.java index b6b7adf..df60990 100644 --- a/graphics/java/android/renderscript/Type.java +++ b/graphics/java/android/renderscript/Type.java @@ -23,13 +23,74 @@ import java.lang.reflect.Field; * **/ public class Type extends BaseObj { - Dimension[] mDimensions; - int[] mValues; + int mDimX; + int mDimY; + int mDimZ; + boolean mDimLOD; + boolean mDimFaces; + int mElementCount; Element mElement; + private int mNativeCache; Class mJavaClass; + public int getX() { + return mDimX; + } + public int getY() { + return mDimY; + } + public int getZ() { + return mDimZ; + } + public boolean getLOD() { + return mDimLOD; + } + public boolean getFaces() { + return mDimFaces; + } + public int getElementCount() { + return mElementCount; + } + + void calcElementCount() { + boolean hasLod = getLOD(); + int x = getX(); + int y = getY(); + int z = getZ(); + int faces = 1; + if(getFaces()) { + faces = 6; + } + if(x == 0) { + x = 1; + } + if(y == 0) { + y = 1; + } + if(z == 0) { + z = 1; + } + + int count = x * y * z * faces; + if(hasLod && (x > 1) && (y > 1) && (z > 1)) { + if(x > 1) { + x >>= 1; + } + if(y > 1) { + y >>= 1; + } + if(z > 1) { + z >>= 1; + } + + count += x * y * z * faces; + } + mElementCount = count; + } + + Type(int id, RenderScript rs) { super(rs); mID = id; @@ -131,12 +192,25 @@ public class Type extends BaseObj { public Type create() { Type t = internalCreate(mRS, this); t.mElement = mElement; - t.mDimensions = new Dimension[mEntryCount]; - t.mValues = new int[mEntryCount]; + for(int ct=0; ct < mEntryCount; ct++) { - t.mDimensions[ct] = mEntries[ct].mDim; - t.mValues[ct] = mEntries[ct].mValue; + if(mEntries[ct].mDim == Dimension.X) { + t.mDimX = mEntries[ct].mValue; + } + if(mEntries[ct].mDim == Dimension.Y) { + t.mDimY = mEntries[ct].mValue; + } + if(mEntries[ct].mDim == Dimension.Z) { + t.mDimZ = mEntries[ct].mValue; + } + if(mEntries[ct].mDim == Dimension.LOD) { + t.mDimLOD = mEntries[ct].mValue != 0; + } + if(mEntries[ct].mDim == Dimension.FACE) { + t.mDimFaces = mEntries[ct].mValue != 0; + } } + t.calcElementCount(); return t; } } |