1dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross/*
2dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross * Copyright (C) 2015 The Android Open Source Project
3dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross *
4dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross * Licensed under the Apache License, Version 2.0 (the "License");
5dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross * you may not use this file except in compliance with the License.
6dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross * You may obtain a copy of the License at
7dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross *
8dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross *      http://www.apache.org/licenses/LICENSE-2.0
9dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross *
10dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross * Unless required by applicable law or agreed to in writing, software
11dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross * distributed under the License is distributed on an "AS IS" BASIS,
12dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross * See the License for the specific language governing permissions and
14dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross * limitations under the License.
15dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross */
16dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross
17dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Grosspackage com.android.rs.test;
18dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross
19dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Grossimport android.content.Context;
20c619e32616d4f6f02fb4bc74a6e6907270fc7c4eMiao Wangimport android.renderscript.Allocation;
21c619e32616d4f6f02fb4bc74a6e6907270fc7c4eMiao Wangimport android.renderscript.Element;
22c619e32616d4f6f02fb4bc74a6e6907270fc7c4eMiao Wangimport android.renderscript.RenderScript;
23c619e32616d4f6f02fb4bc74a6e6907270fc7c4eMiao Wangimport android.renderscript.Type;
24dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross
25dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Grosspublic class UT_kernel2d_oldstyle extends UnitTest {
261c3a11a3287d971458a021d16a54e16b37f391f9Yang Ni    private Type T;
27dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross    private Allocation A;
28dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross    private Allocation B;
29dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross
3033709e1da5e801ca331642c25a61847ced8539e8Miao Wang    protected UT_kernel2d_oldstyle(RSTestCore rstc, Context ctx) {
31dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross        super(rstc, "Kernel 2d (old style)", ctx);
32dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross    }
33dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross
34dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross    private void initializeGlobals(RenderScript RS, ScriptC_kernel2d_oldstyle s) {
35dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross        Type.Builder typeBuilder = new Type.Builder(RS, Element.I32(RS));
36dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross        int X = 2;
37dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross        s.set_gDimX(X);
38dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross        typeBuilder.setX(X);
39dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross        int Y = 5;
40dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross        s.set_gDimY(Y);
41dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross        typeBuilder.setY(Y);
42dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross
431c3a11a3287d971458a021d16a54e16b37f391f9Yang Ni        T = typeBuilder.create();
441c3a11a3287d971458a021d16a54e16b37f391f9Yang Ni        A = Allocation.createTyped(RS, T);
45dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross        s.set_A(A);
461c3a11a3287d971458a021d16a54e16b37f391f9Yang Ni        B = Allocation.createTyped(RS, T);
47dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross        s.set_B(B);
48dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross        return;
49dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross    }
50dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross
51dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross    public void run() {
52dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross        RenderScript pRS = RenderScript.create(mCtx);
53dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross        ScriptC_kernel2d_oldstyle s = new ScriptC_kernel2d_oldstyle(pRS);
54dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross        pRS.setMessageHandler(mRsMessage);
55dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross        initializeGlobals(pRS, s);
56dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross        s.forEach_init_vars(A);
57dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross        s.forEach_xform(A, B);
58dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross        s.invoke_verify_xform();
59dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross        s.invoke_kernel_test();
60dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross        pRS.finish();
61dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross        waitForMessage();
621c3a11a3287d971458a021d16a54e16b37f391f9Yang Ni        T.destroy();
631c3a11a3287d971458a021d16a54e16b37f391f9Yang Ni        A.destroy();
641c3a11a3287d971458a021d16a54e16b37f391f9Yang Ni        B.destroy();
651c3a11a3287d971458a021d16a54e16b37f391f9Yang Ni        s.destroy();
66dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross        pRS.destroy();
67dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross    }
68dced5c96bc53c45a1aac782ea9bd738b0d50fd09David Gross}
69