149a05d7b82956009f03acbb92a064eed054eb031Jason Sams/* 249a05d7b82956009f03acbb92a064eed054eb031Jason Sams * Copyright (C) 2008 The Android Open Source Project 349a05d7b82956009f03acbb92a064eed054eb031Jason Sams * 449a05d7b82956009f03acbb92a064eed054eb031Jason Sams * Licensed under the Apache License, Version 2.0 (the "License"); 549a05d7b82956009f03acbb92a064eed054eb031Jason Sams * you may not use this file except in compliance with the License. 649a05d7b82956009f03acbb92a064eed054eb031Jason Sams * You may obtain a copy of the License at 749a05d7b82956009f03acbb92a064eed054eb031Jason Sams * 849a05d7b82956009f03acbb92a064eed054eb031Jason Sams * http://www.apache.org/licenses/LICENSE-2.0 949a05d7b82956009f03acbb92a064eed054eb031Jason Sams * 1049a05d7b82956009f03acbb92a064eed054eb031Jason Sams * Unless required by applicable law or agreed to in writing, software 1149a05d7b82956009f03acbb92a064eed054eb031Jason Sams * distributed under the License is distributed on an "AS IS" BASIS, 1249a05d7b82956009f03acbb92a064eed054eb031Jason Sams * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1349a05d7b82956009f03acbb92a064eed054eb031Jason Sams * See the License for the specific language governing permissions and 1449a05d7b82956009f03acbb92a064eed054eb031Jason Sams * limitations under the License. 1549a05d7b82956009f03acbb92a064eed054eb031Jason Sams */ 1649a05d7b82956009f03acbb92a064eed054eb031Jason Sams 1749a05d7b82956009f03acbb92a064eed054eb031Jason Samspackage android.renderscript; 1849a05d7b82956009f03acbb92a064eed054eb031Jason Sams 199c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines/** 20c11e25c4e653124def1fb18e203b894f42106cbeTim Murray * Only intended for use by generated reflected code. 2149a05d7b82956009f03acbb92a064eed054eb031Jason Sams * 2249a05d7b82956009f03acbb92a064eed054eb031Jason Sams **/ 2349a05d7b82956009f03acbb92a064eed054eb031Jason Samspublic class AllocationAdapter extends Allocation { 2446ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams Type mWindow; 2546ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams 2646ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams AllocationAdapter(long id, RenderScript rs, Allocation alloc, Type t) { 27ba862d1544a06528151550be1784a926ee986580Jason Sams super(id, rs, alloc.mType, alloc.mUsage); 28ba862d1544a06528151550be1784a926ee986580Jason Sams mAdaptedAllocation = alloc; 2946ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams mWindow = t; 3049a05d7b82956009f03acbb92a064eed054eb031Jason Sams } 3149a05d7b82956009f03acbb92a064eed054eb031Jason Sams 3246ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams /* 33460a04971c494fec39ffcb38e873bb8fdd82d113Tim Murray long getID(RenderScript rs) { 3448fe534838d8b9d10f98ea2662eec258320ab4e7Jason Sams throw new RSInvalidStateException( 3548fe534838d8b9d10f98ea2662eec258320ab4e7Jason Sams "This operation is not supported with adapters at this time."); 36ee2d809ab099e67698a37f13a42d22eaa2251f77Jason Sams } 3746ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams */ 3849a05d7b82956009f03acbb92a064eed054eb031Jason Sams 39ba862d1544a06528151550be1784a926ee986580Jason Sams void initLOD(int lod) { 40ee2d809ab099e67698a37f13a42d22eaa2251f77Jason Sams if (lod < 0) { 41ee2d809ab099e67698a37f13a42d22eaa2251f77Jason Sams throw new RSIllegalArgumentException("Attempting to set negative lod (" + lod + ")."); 42ee2d809ab099e67698a37f13a42d22eaa2251f77Jason Sams } 43ee2d809ab099e67698a37f13a42d22eaa2251f77Jason Sams 44ba862d1544a06528151550be1784a926ee986580Jason Sams int tx = mAdaptedAllocation.mType.getX(); 45ba862d1544a06528151550be1784a926ee986580Jason Sams int ty = mAdaptedAllocation.mType.getY(); 46ba862d1544a06528151550be1784a926ee986580Jason Sams int tz = mAdaptedAllocation.mType.getZ(); 47ee2d809ab099e67698a37f13a42d22eaa2251f77Jason Sams 48ee2d809ab099e67698a37f13a42d22eaa2251f77Jason Sams for (int ct=0; ct < lod; ct++) { 49ee2d809ab099e67698a37f13a42d22eaa2251f77Jason Sams if ((tx==1) && (ty == 1) && (tz == 1)) { 50ee2d809ab099e67698a37f13a42d22eaa2251f77Jason Sams throw new RSIllegalArgumentException("Attempting to set lod (" + lod + ") out of range."); 51ee2d809ab099e67698a37f13a42d22eaa2251f77Jason Sams } 52ee2d809ab099e67698a37f13a42d22eaa2251f77Jason Sams 53ee2d809ab099e67698a37f13a42d22eaa2251f77Jason Sams if (tx > 1) tx >>= 1; 54ee2d809ab099e67698a37f13a42d22eaa2251f77Jason Sams if (ty > 1) ty >>= 1; 55ee2d809ab099e67698a37f13a42d22eaa2251f77Jason Sams if (tz > 1) tz >>= 1; 56ee2d809ab099e67698a37f13a42d22eaa2251f77Jason Sams } 57ee2d809ab099e67698a37f13a42d22eaa2251f77Jason Sams 58ba862d1544a06528151550be1784a926ee986580Jason Sams mCurrentDimX = tx; 59ba862d1544a06528151550be1784a926ee986580Jason Sams mCurrentDimY = ty; 60ba862d1544a06528151550be1784a926ee986580Jason Sams mCurrentDimZ = tz; 61ba862d1544a06528151550be1784a926ee986580Jason Sams mCurrentCount = mCurrentDimX; 62ba862d1544a06528151550be1784a926ee986580Jason Sams if (mCurrentDimY > 1) { 63ba862d1544a06528151550be1784a926ee986580Jason Sams mCurrentCount *= mCurrentDimY; 64ee2d809ab099e67698a37f13a42d22eaa2251f77Jason Sams } 65ba862d1544a06528151550be1784a926ee986580Jason Sams if (mCurrentDimZ > 1) { 66ba862d1544a06528151550be1784a926ee986580Jason Sams mCurrentCount *= mCurrentDimZ; 67ee2d809ab099e67698a37f13a42d22eaa2251f77Jason Sams } 68ba862d1544a06528151550be1784a926ee986580Jason Sams mSelectedY = 0; 69ba862d1544a06528151550be1784a926ee986580Jason Sams mSelectedZ = 0; 70ee2d809ab099e67698a37f13a42d22eaa2251f77Jason Sams } 71ee2d809ab099e67698a37f13a42d22eaa2251f77Jason Sams 7246ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams private void updateOffsets() { 7346ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams int a1 = 0, a2 = 0, a3 = 0, a4 = 0; 7446ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams 75add04be7c8411aa5985d27d20c1c6466115d0498Jason Sams if (mSelectedArray != null) { 76add04be7c8411aa5985d27d20c1c6466115d0498Jason Sams if (mSelectedArray.length > 0) { 77add04be7c8411aa5985d27d20c1c6466115d0498Jason Sams a1 = mSelectedArray[0]; 78add04be7c8411aa5985d27d20c1c6466115d0498Jason Sams } 79add04be7c8411aa5985d27d20c1c6466115d0498Jason Sams if (mSelectedArray.length > 1) { 80add04be7c8411aa5985d27d20c1c6466115d0498Jason Sams a2 = mSelectedArray[2]; 81add04be7c8411aa5985d27d20c1c6466115d0498Jason Sams } 82add04be7c8411aa5985d27d20c1c6466115d0498Jason Sams if (mSelectedArray.length > 2) { 83add04be7c8411aa5985d27d20c1c6466115d0498Jason Sams a3 = mSelectedArray[2]; 84add04be7c8411aa5985d27d20c1c6466115d0498Jason Sams } 85add04be7c8411aa5985d27d20c1c6466115d0498Jason Sams if (mSelectedArray.length > 3) { 86add04be7c8411aa5985d27d20c1c6466115d0498Jason Sams a4 = mSelectedArray[3]; 87add04be7c8411aa5985d27d20c1c6466115d0498Jason Sams } 8846ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams } 8946ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams mRS.nAllocationAdapterOffset(getID(mRS), mSelectedX, mSelectedY, mSelectedZ, 9046ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams mSelectedLOD, mSelectedFace.mID, a1, a2, a3, a4); 9146ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams 9246ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams } 9346ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams 949c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines /** 95ee2d809ab099e67698a37f13a42d22eaa2251f77Jason Sams * Set the active LOD. The LOD must be within the range for the 96ba862d1544a06528151550be1784a926ee986580Jason Sams * type being adapted. The base allocation must have mipmaps. 97ba862d1544a06528151550be1784a926ee986580Jason Sams * 98ba862d1544a06528151550be1784a926ee986580Jason Sams * Because this changes the dimensions of the adapter the 99ba862d1544a06528151550be1784a926ee986580Jason Sams * current Y and Z will be reset. 100ee2d809ab099e67698a37f13a42d22eaa2251f77Jason Sams * 101ee2d809ab099e67698a37f13a42d22eaa2251f77Jason Sams * @param lod The LOD to make active. 102ee2d809ab099e67698a37f13a42d22eaa2251f77Jason Sams */ 10349a05d7b82956009f03acbb92a064eed054eb031Jason Sams public void setLOD(int lod) { 104ba862d1544a06528151550be1784a926ee986580Jason Sams if (!mAdaptedAllocation.getType().hasMipmaps()) { 105ee2d809ab099e67698a37f13a42d22eaa2251f77Jason Sams throw new RSInvalidStateException("Cannot set LOD when the allocation type does not include mipmaps."); 106ee2d809ab099e67698a37f13a42d22eaa2251f77Jason Sams } 10746ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams if (mWindow.hasMipmaps()) { 108ee2d809ab099e67698a37f13a42d22eaa2251f77Jason Sams throw new RSInvalidStateException("Cannot set LOD when the adapter includes mipmaps."); 109ee2d809ab099e67698a37f13a42d22eaa2251f77Jason Sams } 110ee2d809ab099e67698a37f13a42d22eaa2251f77Jason Sams 111ee2d809ab099e67698a37f13a42d22eaa2251f77Jason Sams initLOD(lod); 11246ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams mSelectedLOD = lod; 11346ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams updateOffsets(); 11449a05d7b82956009f03acbb92a064eed054eb031Jason Sams } 11549a05d7b82956009f03acbb92a064eed054eb031Jason Sams 1169c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines /** 117ba862d1544a06528151550be1784a926ee986580Jason Sams * Set the active Face. The base allocation must be of a type 118ba862d1544a06528151550be1784a926ee986580Jason Sams * that includes faces. 119ba862d1544a06528151550be1784a926ee986580Jason Sams * 120ba862d1544a06528151550be1784a926ee986580Jason Sams * @param cf The face to make active. 121ba862d1544a06528151550be1784a926ee986580Jason Sams */ 12249a05d7b82956009f03acbb92a064eed054eb031Jason Sams public void setFace(Type.CubemapFace cf) { 123ba862d1544a06528151550be1784a926ee986580Jason Sams if (!mAdaptedAllocation.getType().hasFaces()) { 124ba862d1544a06528151550be1784a926ee986580Jason Sams throw new RSInvalidStateException("Cannot set Face when the allocation type does not include faces."); 125ba862d1544a06528151550be1784a926ee986580Jason Sams } 12646ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams if (mWindow.hasFaces()) { 12746ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams throw new RSInvalidStateException("Cannot set face when the adapter includes faces."); 128ba862d1544a06528151550be1784a926ee986580Jason Sams } 129ba862d1544a06528151550be1784a926ee986580Jason Sams if (cf == null) { 130ba862d1544a06528151550be1784a926ee986580Jason Sams throw new RSIllegalArgumentException("Cannot set null face."); 131ba862d1544a06528151550be1784a926ee986580Jason Sams } 132ba862d1544a06528151550be1784a926ee986580Jason Sams 133304b1f5497155bcf91e7b855cfab7a675e80bf26Alex Sakhartchouk mSelectedFace = cf; 13446ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams updateOffsets(); 13546ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams } 13646ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams 13746ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams 13846ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams /** 139206666790ad35c5dcea3de1f85424ad6a5abbb4dJason Sams * 14046ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams * Set the active X. The x value must be within the range for 14146ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams * the allocation being adapted. 14246ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams * 14346ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams * @param x The x to make active. 14446ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams */ 14546ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams public void setX(int x) { 14646ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams if (mAdaptedAllocation.getType().getX() <= x) { 14746ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams throw new RSInvalidStateException("Cannot set X greater than dimension of allocation."); 14846ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams } 14946ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams if (mWindow.getX() == mAdaptedAllocation.getType().getX()) { 15046ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams throw new RSInvalidStateException("Cannot set X when the adapter includes X."); 15146ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams } 15246ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams if ((mWindow.getX() + x) >= mAdaptedAllocation.getType().getX()) { 15346ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams throw new RSInvalidStateException("Cannot set (X + window) which would be larger than dimension of allocation."); 15446ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams } 15546ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams 15646ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams mSelectedX = x; 15746ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams updateOffsets(); 15849a05d7b82956009f03acbb92a064eed054eb031Jason Sams } 15949a05d7b82956009f03acbb92a064eed054eb031Jason Sams 1609c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines /** 161ba862d1544a06528151550be1784a926ee986580Jason Sams * Set the active Y. The y value must be within the range for 162ba862d1544a06528151550be1784a926ee986580Jason Sams * the allocation being adapted. The base allocation must 163ba862d1544a06528151550be1784a926ee986580Jason Sams * contain the Y dimension. 164ba862d1544a06528151550be1784a926ee986580Jason Sams * 165ba862d1544a06528151550be1784a926ee986580Jason Sams * @param y The y to make active. 166ba862d1544a06528151550be1784a926ee986580Jason Sams */ 16749a05d7b82956009f03acbb92a064eed054eb031Jason Sams public void setY(int y) { 168ba862d1544a06528151550be1784a926ee986580Jason Sams if (mAdaptedAllocation.getType().getY() == 0) { 169ba862d1544a06528151550be1784a926ee986580Jason Sams throw new RSInvalidStateException("Cannot set Y when the allocation type does not include Y dim."); 170ba862d1544a06528151550be1784a926ee986580Jason Sams } 171ba862d1544a06528151550be1784a926ee986580Jason Sams if (mAdaptedAllocation.getType().getY() <= y) { 172ba862d1544a06528151550be1784a926ee986580Jason Sams throw new RSInvalidStateException("Cannot set Y greater than dimension of allocation."); 173ba862d1544a06528151550be1784a926ee986580Jason Sams } 17446ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams if (mWindow.getY() == mAdaptedAllocation.getType().getY()) { 175ba862d1544a06528151550be1784a926ee986580Jason Sams throw new RSInvalidStateException("Cannot set Y when the adapter includes Y."); 176ba862d1544a06528151550be1784a926ee986580Jason Sams } 17746ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams if ((mWindow.getY() + y) >= mAdaptedAllocation.getType().getY()) { 17846ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams throw new RSInvalidStateException("Cannot set (Y + window) which would be larger than dimension of allocation."); 17946ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams } 180ba862d1544a06528151550be1784a926ee986580Jason Sams 181ba862d1544a06528151550be1784a926ee986580Jason Sams mSelectedY = y; 18246ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams updateOffsets(); 18349a05d7b82956009f03acbb92a064eed054eb031Jason Sams } 18449a05d7b82956009f03acbb92a064eed054eb031Jason Sams 1859c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines /** 186ba862d1544a06528151550be1784a926ee986580Jason Sams * Set the active Z. The z value must be within the range for 187ba862d1544a06528151550be1784a926ee986580Jason Sams * the allocation being adapted. The base allocation must 188ba862d1544a06528151550be1784a926ee986580Jason Sams * contain the Z dimension. 189ba862d1544a06528151550be1784a926ee986580Jason Sams * 190ba862d1544a06528151550be1784a926ee986580Jason Sams * @param z The z to make active. 191ba862d1544a06528151550be1784a926ee986580Jason Sams */ 19249a05d7b82956009f03acbb92a064eed054eb031Jason Sams public void setZ(int z) { 193ba862d1544a06528151550be1784a926ee986580Jason Sams if (mAdaptedAllocation.getType().getZ() == 0) { 194ba862d1544a06528151550be1784a926ee986580Jason Sams throw new RSInvalidStateException("Cannot set Z when the allocation type does not include Z dim."); 195ba862d1544a06528151550be1784a926ee986580Jason Sams } 196ba862d1544a06528151550be1784a926ee986580Jason Sams if (mAdaptedAllocation.getType().getZ() <= z) { 197ba862d1544a06528151550be1784a926ee986580Jason Sams throw new RSInvalidStateException("Cannot set Z greater than dimension of allocation."); 198ba862d1544a06528151550be1784a926ee986580Jason Sams } 19946ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams if (mWindow.getZ() == mAdaptedAllocation.getType().getZ()) { 200ba862d1544a06528151550be1784a926ee986580Jason Sams throw new RSInvalidStateException("Cannot set Z when the adapter includes Z."); 201ba862d1544a06528151550be1784a926ee986580Jason Sams } 20246ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams if ((mWindow.getZ() + z) >= mAdaptedAllocation.getType().getZ()) { 20346ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams throw new RSInvalidStateException("Cannot set (Z + window) which would be larger than dimension of allocation."); 20446ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams } 205ba862d1544a06528151550be1784a926ee986580Jason Sams 206ba862d1544a06528151550be1784a926ee986580Jason Sams mSelectedZ = z; 20746ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams updateOffsets(); 20846ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams } 20946ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams 21046ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams /** 211d016266de2cefe12853dbf4a81292b96bb4150b1Jason Sams * @hide 21246ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams */ 21346ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams public void setArray(int arrayNum, int arrayVal) { 21446ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams if (mAdaptedAllocation.getType().getArray(arrayNum) == 0) { 21546ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams throw new RSInvalidStateException("Cannot set arrayNum when the allocation type does not include arrayNum dim."); 21646ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams } 21746ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams if (mAdaptedAllocation.getType().getArray(arrayNum) <= arrayVal) { 21846ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams throw new RSInvalidStateException("Cannot set arrayNum greater than dimension of allocation."); 21946ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams } 22046ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams if (mWindow.getArray(arrayNum) == mAdaptedAllocation.getType().getArray(arrayNum)) { 22146ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams throw new RSInvalidStateException("Cannot set arrayNum when the adapter includes arrayNum."); 22246ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams } 22346ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams if ((mWindow.getArray(arrayNum) + arrayVal) >= mAdaptedAllocation.getType().getArray(arrayNum)) { 22446ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams throw new RSInvalidStateException("Cannot set (arrayNum + window) which would be larger than dimension of allocation."); 22546ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams } 22646ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams 22746ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams mSelectedArray[arrayNum] = arrayVal; 22846ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams updateOffsets(); 22949a05d7b82956009f03acbb92a064eed054eb031Jason Sams } 23049a05d7b82956009f03acbb92a064eed054eb031Jason Sams 231ba862d1544a06528151550be1784a926ee986580Jason Sams static public AllocationAdapter create1D(RenderScript rs, Allocation a) { 232ba862d1544a06528151550be1784a926ee986580Jason Sams rs.validate(); 23346ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams Type t = Type.createX(rs, a.getElement(), a.getType().getX()); 23446ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams return createTyped(rs, a, t); 235ba862d1544a06528151550be1784a926ee986580Jason Sams } 23649a05d7b82956009f03acbb92a064eed054eb031Jason Sams 23746ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams 23849a05d7b82956009f03acbb92a064eed054eb031Jason Sams static public AllocationAdapter create2D(RenderScript rs, Allocation a) { 23949a05d7b82956009f03acbb92a064eed054eb031Jason Sams rs.validate(); 24046ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams Type t = Type.createXY(rs, a.getElement(), a.getType().getX(), a.getType().getY()); 24146ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams return createTyped(rs, a, t); 24249a05d7b82956009f03acbb92a064eed054eb031Jason Sams } 24349a05d7b82956009f03acbb92a064eed054eb031Jason Sams 24446ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams /** 245206666790ad35c5dcea3de1f85424ad6a5abbb4dJason Sams * 24646ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams * 247115b4117a0c19a31231d4df5f2b73c6c88e6726cPirama Arumuga Nainar * Create an arbitrary window into the base allocation. 24846ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams * The type describes the shape of the window. 24946ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams * 25046ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams * Any dimensions present in the type must be equal or smaller 25146ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams * to the dimensions in the source allocation. A dimension 25246ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams * present in the allocation that is not present in the type 253115b4117a0c19a31231d4df5f2b73c6c88e6726cPirama Arumuga Nainar * will be constrained away with the selectors. 25446ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams * 255115b4117a0c19a31231d4df5f2b73c6c88e6726cPirama Arumuga Nainar * If a dimension is present in both the type and allocation, one of 256115b4117a0c19a31231d4df5f2b73c6c88e6726cPirama Arumuga Nainar * two things will happen. 25746ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams * 258115b4117a0c19a31231d4df5f2b73c6c88e6726cPirama Arumuga Nainar * If the type is smaller than the allocation, a window will be 25946ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams * created, the selected value in the adapter for that dimension 260115b4117a0c19a31231d4df5f2b73c6c88e6726cPirama Arumuga Nainar * will act as the base address, and the type will describe the 26146ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams * size of the view starting at that point. 26246ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams * 263115b4117a0c19a31231d4df5f2b73c6c88e6726cPirama Arumuga Nainar * If the type and allocation dimension are of the same size, 26446ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams * then setting the selector for the dimension will be an error. 26546ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams */ 26646ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams static public AllocationAdapter createTyped(RenderScript rs, Allocation a, Type t) { 26746ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams rs.validate(); 26846ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams 26946ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams if (a.mAdaptedAllocation != null) { 27046ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams throw new RSInvalidStateException("Adapters cannot be nested."); 27146ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams } 27246ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams 27346ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams if (!a.getType().getElement().equals(t.getElement())) { 27446ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams throw new RSInvalidStateException("Element must match Allocation type."); 27546ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams } 27646ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams 27746ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams if (t.hasFaces() || t.hasMipmaps()) { 27846ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams throw new RSInvalidStateException("Adapters do not support window types with Mipmaps or Faces."); 27946ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams } 28046ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams 28146ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams Type at = a.getType(); 28246ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams if ((t.getX() > at.getX()) || 28346ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams (t.getY() > at.getY()) || 28446ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams (t.getZ() > at.getZ()) || 28546ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams (t.getArrayCount() > at.getArrayCount())) { 28646ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams 28746ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams throw new RSInvalidStateException("Type cannot have dimension larger than the source allocation."); 28846ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams } 28946ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams 29046ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams if (t.getArrayCount() > 0) { 29146ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams for (int i = 0; i < t.getArray(i); i++) { 29246ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams if (t.getArray(i) > at.getArray(i)) { 29346ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams throw new RSInvalidStateException("Type cannot have dimension larger than the source allocation."); 29446ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams } 29546ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams } 29646ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams } 29746ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams 29846ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams // Create the object 29946ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams long id = rs.nAllocationAdapterCreate(a.getID(rs), t.getID(rs)); 30046ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams if (id == 0) { 30146ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams throw new RSRuntimeException("AllocationAdapter creation failed."); 30246ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams } 30346ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams return new AllocationAdapter(id, rs, a, t); 30446ba27e3fdcf1ce3b940e8b2ec90fcd2c9b7fe43Jason Sams } 30549a05d7b82956009f03acbb92a064eed054eb031Jason Sams 3069c9ad3f8c218954e46aab81f9af7834cea5675caStephen Hines /** 307ba862d1544a06528151550be1784a926ee986580Jason Sams * Override the Allocation resize. Resizing adapters is not 308ba862d1544a06528151550be1784a926ee986580Jason Sams * allowed and will throw a RSInvalidStateException. 309ba862d1544a06528151550be1784a926ee986580Jason Sams * 310ba862d1544a06528151550be1784a926ee986580Jason Sams * @param dimX ignored. 311ba862d1544a06528151550be1784a926ee986580Jason Sams */ 312ba862d1544a06528151550be1784a926ee986580Jason Sams public synchronized void resize(int dimX) { 313ba862d1544a06528151550be1784a926ee986580Jason Sams throw new RSInvalidStateException("Resize not allowed for Adapters."); 314ba862d1544a06528151550be1784a926ee986580Jason Sams } 315ba862d1544a06528151550be1784a926ee986580Jason Sams 31649a05d7b82956009f03acbb92a064eed054eb031Jason Sams} 31749a05d7b82956009f03acbb92a064eed054eb031Jason Sams 31849a05d7b82956009f03acbb92a064eed054eb031Jason Sams 319