Home | History | Annotate | Download | only in branchingfuncalls
      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.branchingfuncalls;
     18 
     19 import android.app.Activity;
     20 import android.os.Bundle;
     21 import android.renderscript.*;
     22 
     23 public class MainActivity extends Activity {
     24     private RenderScript mRS;
     25     private Allocation mInAllocation;
     26     private Allocation mOutAllocation;
     27     private ScriptC_scalars mScript;
     28     private int mAllocSize = 256;
     29 
     30     @Override
     31     protected void onCreate(Bundle savedInstanceState) {
     32         super.onCreate(savedInstanceState);
     33 
     34         setContentView(R.layout.main_layout);
     35         createScript();
     36         runScript();
     37     }
     38 
     39     private void createScript() {
     40         mRS = RenderScript.create(this,
     41             RenderScript.ContextType.NORMAL,
     42             RenderScript.CREATE_FLAG_LOW_LATENCY |
     43             RenderScript.CREATE_FLAG_WAIT_FOR_ATTACH);
     44 
     45         Element e = Element.I32(mRS);
     46         mInAllocation = Allocation.createSized(mRS, e, mAllocSize);
     47         mOutAllocation = Allocation.createSized(mRS, e, mAllocSize);
     48 
     49         mScript = new ScriptC_scalars(mRS);
     50     }
     51 
     52     private void runScript() {
     53         mScript.invoke_addToGlobal(234);
     54 
     55         int[] init = new int[mAllocSize];
     56         for(int i = 0; i < mAllocSize; ++i) {
     57             init[i] = i - (mAllocSize / 2);
     58         }
     59         mInAllocation.copy1DRangeFrom(0, mAllocSize, init);
     60         mScript.forEach_simple_kernel(mInAllocation, mOutAllocation);
     61     }
     62 }
     63 
     64