1 /*
2 * Copyright (C) 2016 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 com.android.rs.scriptgroup;
18 
19 import android.app.Activity;
20 import android.graphics.Bitmap;
21 import android.os.Bundle;
22 import android.widget.ImageView;
23 import android.renderscript.*;
24 
25 public class MainActivity extends Activity {
26     private static final int ARRAY_SIZE = 8;
27 
28     @Override
onCreate(Bundle savedInstanceState)29     protected void onCreate(Bundle savedInstanceState) {
30         super.onCreate(savedInstanceState);
31         setContentView(R.layout.main_layout);
32 
33         // create renderscript context
34         RenderScript pRS = RenderScript.create(this, RenderScript.ContextType.NORMAL,
35             RenderScript.CREATE_FLAG_WAIT_FOR_ATTACH | RenderScript.CREATE_FLAG_LOW_LATENCY);
36 
37         ScriptC_scriptgroup script = new ScriptC_scriptgroup(pRS);
38 
39         // create and initalize a simple input allocation
40         int[] array = new int[ARRAY_SIZE];
41         for (int i = 0; i < ARRAY_SIZE; i++) {
42             array[i] = i;
43         }
44         Allocation input = Allocation.createSized(pRS, Element.I32(pRS), ARRAY_SIZE);
45         input.copyFrom(array);
46 
47         ScriptGroup.Builder2 builder = new ScriptGroup.Builder2(pRS);
48 
49         ScriptGroup.Input unbound = builder.addInput();
50 
51         ScriptGroup.Closure c0 = builder.addKernel(
52             script.getKernelID_foo(), Type.createX(pRS, Element.I32(pRS), ARRAY_SIZE), unbound);
53 
54         ScriptGroup.Closure c1 = builder.addKernel(script.getKernelID_goo(),
55             Type.createX(pRS, Element.I32(pRS), ARRAY_SIZE), c0.getReturn());
56 
57         ScriptGroup group = builder.create("scriptgroup_test", c1.getReturn());
58 
59         int[] a = new int[ARRAY_SIZE];
60         ((Allocation) group.execute(input)[0]).copyTo(a);
61 
62         pRS.finish();
63         pRS.destroy();
64     }
65 }
66