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 import android.renderscript.Allocation; 20 import android.renderscript.Element; 21 import android.renderscript.Type; 22 import java.util.Random; 23 24 public class AllocationCopy2DRangeTest extends RSBaseCompute { 25 private Allocation mInAllocation; 26 private Allocation mOutAllocation; 27 28 public void testAllocationCopy2DRange() { 29 ScriptC_allocationCopy2DRange mScript = 30 new ScriptC_allocationCopy2DRange(mRS); 31 Random random = new Random(0x172d8ab9); 32 int width = random.nextInt(512); 33 int height = random.nextInt(512); 34 35 int[] inArray = new int[width * height]; 36 int[] outArray = new int[width * height]; 37 38 for (int i = 0; i < width * height; i++) { 39 inArray[i] = random.nextInt(); 40 } 41 42 // Create 2D data. 43 Type.Builder typeBuilder = new Type.Builder(mRS, Element.I32(mRS)); 44 typeBuilder.setX(width).setY(height); 45 mInAllocation = Allocation.createTyped(mRS, typeBuilder.create()); 46 mOutAllocation = Allocation.createTyped(mRS, mInAllocation.getType()); 47 mInAllocation.copy2DRangeFrom(0, 0, width, height, inArray); 48 49 mScript.set_height(height); 50 mScript.set_width(width); 51 mScript.set_mIn(mInAllocation); 52 mScript.set_mOut(mOutAllocation); 53 54 mScript.invoke_testAllocationCopy2DRange(); 55 mOutAllocation.copyTo(outArray); 56 assertTrue("testAllocationCopy2DRange failed, output array does not match input", 57 compareTwoArrays(inArray, outArray, width*height)); 58 59 mInAllocation.destroy(); 60 mOutAllocation.destroy(); 61 } 62 63 private boolean compareTwoArrays(int[] src, int[] dest, int size) { 64 boolean result = true; 65 for (int i = 0; i < size; i++) { 66 if (src[i] != dest[i]) { 67 result = false; 68 break; 69 } 70 } 71 return result; 72 } 73 } 74