MainActivity.java revision 1cea94d9a1268eb8b9d0099a4c145de3f8688e07
1package com.android.rs.scriptgroup; 2 3import android.app.Activity; 4import android.graphics.Bitmap; 5import android.os.Bundle; 6import android.widget.ImageView; 7import android.renderscript.*; 8 9public class MainActivity extends Activity { 10 private static final int ARRAY_SIZE = 8; 11 12 @Override 13 protected void onCreate(Bundle savedInstanceState) { 14 super.onCreate(savedInstanceState); 15 setContentView(R.layout.main_layout); 16 17 // create renderscript context 18 RenderScript pRS = RenderScript.create(this, RenderScript.ContextType.NORMAL, 19 RenderScript.CREATE_FLAG_WAIT_FOR_ATTACH | RenderScript.CREATE_FLAG_LOW_LATENCY); 20 21 ScriptC_scriptgroup script = new ScriptC_scriptgroup(pRS); 22 23 // create and initalize a simple input allocation 24 int[] array = new int[ARRAY_SIZE]; 25 for (int i = 0; i < ARRAY_SIZE; i++) { 26 array[i] = i; 27 } 28 Allocation input = Allocation.createSized(pRS, Element.I32(pRS), ARRAY_SIZE); 29 input.copyFrom(array); 30 31 ScriptGroup.Builder2 builder = new ScriptGroup.Builder2(pRS); 32 33 ScriptGroup.Input unbound = builder.addInput(); 34 35 ScriptGroup.Closure c0 = builder.addKernel( 36 script.getKernelID_foo(), Type.createX(pRS, Element.I32(pRS), ARRAY_SIZE), unbound); 37 38 ScriptGroup.Closure c1 = builder.addKernel(script.getKernelID_goo(), 39 Type.createX(pRS, Element.I32(pRS), ARRAY_SIZE), c0.getReturn()); 40 41 ScriptGroup group = builder.create("scriptgroup_test", c1.getReturn()); 42 43 int[] a = new int[ARRAY_SIZE]; 44 ((Allocation) group.execute(input)[0]).copyTo(a); 45 46 pRS.finish(); 47 pRS.destroy(); 48 } 49} 50