1/*
2 * Copyright (C) 2015 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_compat;
18
19import android.content.Context;
20import android.content.res.Resources;
21import android.support.v8.renderscript.*;
22
23public class UT_single_source_script extends UnitTest {
24    private Resources mRes;
25    private Allocation testAllocation1, testAllocation2;
26
27    protected UT_single_source_script(RSTestCore rstc, Resources res, Context ctx) {
28        super(rstc, "SingleSourceScript", ctx);
29        mRes = res;
30    }
31
32    private void initializeGlobals(RenderScript RS, ScriptC_single_source_script s) {
33        Type.Builder i32TypeBuilder = new Type.Builder(RS, Element.I32(RS));
34        int X = 1024;
35        int Y = 768;
36        s.set_dimX(X);
37        s.set_dimY(Y);
38        i32TypeBuilder.setX(X).setY(Y);
39        testAllocation1 = Allocation.createTyped(RS, i32TypeBuilder.create());
40        testAllocation2 = Allocation.createTyped(RS, i32TypeBuilder.create());
41    }
42
43    public void run() {
44        RenderScript pRS = RenderScript.create(mCtx);
45        ScriptC_single_source_script s = new ScriptC_single_source_script(pRS);
46        pRS.setMessageHandler(mRsMessage);
47        initializeGlobals(pRS, s);
48
49        s.invoke_entrypoint(testAllocation1, testAllocation2);
50        s.forEach_oldFoo(testAllocation2, testAllocation2);
51        s.forEach_oldGoo(testAllocation2, testAllocation2);
52        s.invoke_validate(testAllocation2);
53
54        pRS.finish();
55        waitForMessage();
56        s.destroy();
57        testAllocation1.getType().destroy();
58        testAllocation1.destroy();
59        testAllocation2.getType().destroy();
60        testAllocation2.destroy();
61        pRS.destroy();
62    }
63}
64