1/*
2 * Copyright (C) 2013 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
17package com.android.rs.test_compatlegacy;
18
19import android.content.Context;
20import android.content.res.Resources;
21import android.support.v8.renderscript.*;
22import android.util.Log;
23
24public class UT_kernel_struct extends UnitTest {
25    private Resources mRes;
26    private Allocation A;
27    private Allocation B;
28
29    protected UT_kernel_struct(RSTestCore rstc, Resources res, Context ctx) {
30        super(rstc, "Kernels (struct pass-by-value)", ctx);
31        mRes = res;
32    }
33
34    private void initializeGlobals(RenderScript RS, ScriptC_kernel_struct s) {
35        int X = 5;
36        s.set_dimX(X);
37        ScriptField_simpleStruct t;
38        t = new ScriptField_simpleStruct(RS, X);
39        s.bind_ain(t);
40        A = t.getAllocation();
41        t = new ScriptField_simpleStruct(RS, X);
42        s.bind_aout(t);
43        B = t.getAllocation();
44
45        return;
46    }
47
48    public void run() {
49        RenderScript pRS = RenderScript.create(mCtx);
50        ScriptC_kernel_struct s = new ScriptC_kernel_struct(pRS);
51        pRS.setMessageHandler(mRsMessage);
52        initializeGlobals(pRS, s);
53        s.forEach_init_vars(A);
54        s.forEach_root(A, B);
55        s.invoke_verify_root();
56        s.invoke_kernel_struct_test();
57        pRS.finish();
58        waitForMessage();
59        pRS.destroy();
60    }
61}
62