| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.renderscript; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
@Deprecated |
| 27 |
public class AllocationAdapter extends Allocation { |
| 28 |
Type mWindow; |
| 29 |
|
| 30 |
AllocationAdapter(long id, RenderScript rs, Allocation alloc, Type t) { |
| 31 |
super(id, rs, alloc.mType, alloc.mUsage); |
| 32 |
mAdaptedAllocation = alloc; |
| 33 |
mWindow = t; |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
void initLOD(int lod) { |
| 44 |
if (lod < 0) { |
| 45 |
throw new RSIllegalArgumentException("Attempting to set negative lod (" + lod + ")."); |
| 46 |
} |
| 47 |
|
| 48 |
int tx = mAdaptedAllocation.mType.getX(); |
| 49 |
int ty = mAdaptedAllocation.mType.getY(); |
| 50 |
int tz = mAdaptedAllocation.mType.getZ(); |
| 51 |
|
| 52 |
for (int ct=0; ct < lod; ct++) { |
| 53 |
if ((tx==1) && (ty == 1) && (tz == 1)) { |
| 54 |
throw new RSIllegalArgumentException("Attempting to set lod (" + lod + ") out of range."); |
| 55 |
} |
| 56 |
|
| 57 |
if (tx > 1) tx >>= 1; |
| 58 |
if (ty > 1) ty >>= 1; |
| 59 |
if (tz > 1) tz >>= 1; |
| 60 |
} |
| 61 |
|
| 62 |
mCurrentDimX = tx; |
| 63 |
mCurrentDimY = ty; |
| 64 |
mCurrentDimZ = tz; |
| 65 |
mCurrentCount = mCurrentDimX; |
| 66 |
if (mCurrentDimY > 1) { |
| 67 |
mCurrentCount *= mCurrentDimY; |
| 68 |
} |
| 69 |
if (mCurrentDimZ > 1) { |
| 70 |
mCurrentCount *= mCurrentDimZ; |
| 71 |
} |
| 72 |
mSelectedY = 0; |
| 73 |
mSelectedZ = 0; |
| 74 |
} |
| 75 |
|
| 76 |
private void updateOffsets() { |
| 77 |
int a1 = 0, a2 = 0, a3 = 0, a4 = 0; |
| 78 |
|
| 79 |
if (mSelectedArray != null) { |
| 80 |
if (mSelectedArray.length > 0) { |
| 81 |
a1 = mSelectedArray[0]; |
| 82 |
} |
| 83 |
if (mSelectedArray.length > 1) { |
| 84 |
a2 = mSelectedArray[2]; |
| 85 |
} |
| 86 |
if (mSelectedArray.length > 2) { |
| 87 |
a3 = mSelectedArray[2]; |
| 88 |
} |
| 89 |
if (mSelectedArray.length > 3) { |
| 90 |
a4 = mSelectedArray[3]; |
| 91 |
} |
| 92 |
} |
| 93 |
mRS.nAllocationAdapterOffset(getID(mRS), mSelectedX, mSelectedY, mSelectedZ, |
| 94 |
mSelectedLOD, mSelectedFace.mID, a1, a2, a3, a4); |
| 95 |
|
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
public void setLOD(int lod) { |
| 108 |
if (!mAdaptedAllocation.getType().hasMipmaps()) { |
| 109 |
throw new RSInvalidStateException("Cannot set LOD when the allocation type does not include mipmaps."); |
| 110 |
} |
| 111 |
if (mWindow.hasMipmaps()) { |
| 112 |
throw new RSInvalidStateException("Cannot set LOD when the adapter includes mipmaps."); |
| 113 |
} |
| 114 |
|
| 115 |
initLOD(lod); |
| 116 |
mSelectedLOD = lod; |
| 117 |
updateOffsets(); |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
public void setFace(Type.CubemapFace cf) { |
| 127 |
if (!mAdaptedAllocation.getType().hasFaces()) { |
| 128 |
throw new RSInvalidStateException("Cannot set Face when the allocation type does not include faces."); |
| 129 |
} |
| 130 |
if (mWindow.hasFaces()) { |
| 131 |
throw new RSInvalidStateException("Cannot set face when the adapter includes faces."); |
| 132 |
} |
| 133 |
if (cf == null) { |
| 134 |
throw new RSIllegalArgumentException("Cannot set null face."); |
| 135 |
} |
| 136 |
|
| 137 |
mSelectedFace = cf; |
| 138 |
updateOffsets(); |
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
public void setX(int x) { |
| 150 |
if (mAdaptedAllocation.getType().getX() <= x) { |
| 151 |
throw new RSInvalidStateException("Cannot set X greater than dimension of allocation."); |
| 152 |
} |
| 153 |
if (mWindow.getX() == mAdaptedAllocation.getType().getX()) { |
| 154 |
throw new RSInvalidStateException("Cannot set X when the adapter includes X."); |
| 155 |
} |
| 156 |
if ((mWindow.getX() + x) >= mAdaptedAllocation.getType().getX()) { |
| 157 |
throw new RSInvalidStateException("Cannot set (X + window) which would be larger than dimension of allocation."); |
| 158 |
} |
| 159 |
|
| 160 |
mSelectedX = x; |
| 161 |
updateOffsets(); |
| 162 |
} |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
public void setY(int y) { |
| 172 |
if (mAdaptedAllocation.getType().getY() == 0) { |
| 173 |
throw new RSInvalidStateException("Cannot set Y when the allocation type does not include Y dim."); |
| 174 |
} |
| 175 |
if (mAdaptedAllocation.getType().getY() <= y) { |
| 176 |
throw new RSInvalidStateException("Cannot set Y greater than dimension of allocation."); |
| 177 |
} |
| 178 |
if (mWindow.getY() == mAdaptedAllocation.getType().getY()) { |
| 179 |
throw new RSInvalidStateException("Cannot set Y when the adapter includes Y."); |
| 180 |
} |
| 181 |
if ((mWindow.getY() + y) >= mAdaptedAllocation.getType().getY()) { |
| 182 |
throw new RSInvalidStateException("Cannot set (Y + window) which would be larger than dimension of allocation."); |
| 183 |
} |
| 184 |
|
| 185 |
mSelectedY = y; |
| 186 |
updateOffsets(); |
| 187 |
} |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
public void setZ(int z) { |
| 197 |
if (mAdaptedAllocation.getType().getZ() == 0) { |
| 198 |
throw new RSInvalidStateException("Cannot set Z when the allocation type does not include Z dim."); |
| 199 |
} |
| 200 |
if (mAdaptedAllocation.getType().getZ() <= z) { |
| 201 |
throw new RSInvalidStateException("Cannot set Z greater than dimension of allocation."); |
| 202 |
} |
| 203 |
if (mWindow.getZ() == mAdaptedAllocation.getType().getZ()) { |
| 204 |
throw new RSInvalidStateException("Cannot set Z when the adapter includes Z."); |
| 205 |
} |
| 206 |
if ((mWindow.getZ() + z) >= mAdaptedAllocation.getType().getZ()) { |
| 207 |
throw new RSInvalidStateException("Cannot set (Z + window) which would be larger than dimension of allocation."); |
| 208 |
} |
| 209 |
|
| 210 |
mSelectedZ = z; |
| 211 |
updateOffsets(); |
| 212 |
} |
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
public void setArray(int arrayNum, int arrayVal) { |
| 218 |
if (mAdaptedAllocation.getType().getArray(arrayNum) == 0) { |
| 219 |
throw new RSInvalidStateException("Cannot set arrayNum when the allocation type does not include arrayNum dim."); |
| 220 |
} |
| 221 |
if (mAdaptedAllocation.getType().getArray(arrayNum) <= arrayVal) { |
| 222 |
throw new RSInvalidStateException("Cannot set arrayNum greater than dimension of allocation."); |
| 223 |
} |
| 224 |
if (mWindow.getArray(arrayNum) == mAdaptedAllocation.getType().getArray(arrayNum)) { |
| 225 |
throw new RSInvalidStateException("Cannot set arrayNum when the adapter includes arrayNum."); |
| 226 |
} |
| 227 |
if ((mWindow.getArray(arrayNum) + arrayVal) >= mAdaptedAllocation.getType().getArray(arrayNum)) { |
| 228 |
throw new RSInvalidStateException("Cannot set (arrayNum + window) which would be larger than dimension of allocation."); |
| 229 |
} |
| 230 |
|
| 231 |
mSelectedArray[arrayNum] = arrayVal; |
| 232 |
updateOffsets(); |
| 233 |
} |
| 234 |
|
| 235 |
static public AllocationAdapter create1D(RenderScript rs, Allocation a) { |
| 236 |
rs.validate(); |
| 237 |
Type t = Type.createX(rs, a.getElement(), a.getType().getX()); |
| 238 |
return createTyped(rs, a, t); |
| 239 |
} |
| 240 |
|
| 241 |
|
| 242 |
static public AllocationAdapter create2D(RenderScript rs, Allocation a) { |
| 243 |
rs.validate(); |
| 244 |
Type t = Type.createXY(rs, a.getElement(), a.getType().getX(), a.getType().getY()); |
| 245 |
return createTyped(rs, a, t); |
| 246 |
} |
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
static public AllocationAdapter createTyped(RenderScript rs, Allocation a, Type t) { |
| 271 |
rs.validate(); |
| 272 |
|
| 273 |
if (a.mAdaptedAllocation != null) { |
| 274 |
throw new RSInvalidStateException("Adapters cannot be nested."); |
| 275 |
} |
| 276 |
|
| 277 |
if (!a.getType().getElement().equals(t.getElement())) { |
| 278 |
throw new RSInvalidStateException("Element must match Allocation type."); |
| 279 |
} |
| 280 |
|
| 281 |
if (t.hasFaces() || t.hasMipmaps()) { |
| 282 |
throw new RSInvalidStateException("Adapters do not support window types with Mipmaps or Faces."); |
| 283 |
} |
| 284 |
|
| 285 |
Type at = a.getType(); |
| 286 |
if ((t.getX() > at.getX()) || |
| 287 |
(t.getY() > at.getY()) || |
| 288 |
(t.getZ() > at.getZ()) || |
| 289 |
(t.getArrayCount() > at.getArrayCount())) { |
| 290 |
|
| 291 |
throw new RSInvalidStateException("Type cannot have dimension larger than the source allocation."); |
| 292 |
} |
| 293 |
|
| 294 |
if (t.getArrayCount() > 0) { |
| 295 |
for (int i = 0; i < t.getArray(i); i++) { |
| 296 |
if (t.getArray(i) > at.getArray(i)) { |
| 297 |
throw new RSInvalidStateException("Type cannot have dimension larger than the source allocation."); |
| 298 |
} |
| 299 |
} |
| 300 |
} |
| 301 |
|
| 302 |
|
| 303 |
long id = rs.nAllocationAdapterCreate(a.getID(rs), t.getID(rs)); |
| 304 |
if (id == 0) { |
| 305 |
throw new RSRuntimeException("AllocationAdapter creation failed."); |
| 306 |
} |
| 307 |
return new AllocationAdapter(id, rs, a, t); |
| 308 |
} |
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
public synchronized void resize(int dimX) { |
| 317 |
throw new RSInvalidStateException("Resize not allowed for Adapters."); |
| 318 |
} |
| 319 |
|
| 320 |
} |
| 321 |
|
| 322 |
|