1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.renderscript.cts; 18 19 20 import android.renderscript.Allocation; 21 import android.renderscript.Element; 22 import android.renderscript.RSRuntimeException; 23 import java.util.Random; 24 25 public class AllocationResize extends RSBaseCompute { 26 private Allocation mIn; 27 private Allocation mOut; 28 private ScriptC_allocation_resize mScript; 29 30 @Override 31 public void forEach(int testId, Allocation mIn, Allocation mOut) throws RSRuntimeException { 32 mScript.forEach_root(mIn, mOut); 33 } 34 35 public void testResize() { 36 if (mRS.getApplicationContext().getApplicationInfo().targetSdkVersion >= 21) { 37 return; 38 } 39 40 mScript = new ScriptC_allocation_resize(mRS); 41 mIn = Allocation.createSized(mRS, Element.I32(mRS), INPUTSIZE/2); 42 mOut = Allocation.createSized(mRS, Element.I32(mRS), INPUTSIZE*2); 43 mIn.resize(INPUTSIZE); 44 mOut.resize(INPUTSIZE); 45 46 Random random = new Random(0x12345678); 47 int[] outArray = new int[INPUTSIZE]; 48 int[] inArray = new int[INPUTSIZE]; 49 for (int i = 0; i < INPUTSIZE; i++) { 50 inArray[i] = random.nextInt(); 51 } 52 mIn.copy1DRangeFrom(0, INPUTSIZE, inArray); 53 54 try { 55 forEach(0, mIn, mOut); 56 } catch (RSRuntimeException e) { 57 } 58 59 mOut.copyTo(outArray); 60 for (int i = 0; i < INPUTSIZE; i++) { 61 assertEquals("Incorrect value @ idx = " + i + " | ", inArray[i], outArray[i]); 62 } 63 } 64 } 65