1/*
2 * Copyright (C) 2017 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.unittest;
18
19import android.content.Context;
20import android.renderscript.Allocation;
21import android.renderscript.Element;
22import android.renderscript.RenderScript;
23import android.renderscript.Type;
24
25public class UT_alloc extends UnitTest {
26    private Type T;
27    private Type mTFaces;
28    private Type mTLOD;
29    private Type mTFacesLOD;
30    private Allocation mAFaces;
31    private Allocation mALOD;
32    private Allocation mAFacesLOD;
33
34    public UT_alloc(Context ctx) {
35        super("Alloc", ctx);
36    }
37
38    private void initializeGlobals(RenderScript RS, ScriptC_alloc s) {
39        Type.Builder typeBuilder = new Type.Builder(RS, Element.I32(RS));
40        int X = 5;
41        int Y = 7;
42        int Z = 0;
43        s.set_dimX(X);
44        s.set_dimY(Y);
45        s.set_dimZ(Z);
46        typeBuilder.setX(X);  // Only build a 1-D version of this
47        T = typeBuilder.create();
48        Allocation A = Allocation.createTyped(RS, T);
49        s.bind_a(A);
50        s.set_aRaw(A);
51
52        typeBuilder = new Type.Builder(RS, Element.I32(RS));
53        typeBuilder.setX(X).setY(Y).setFaces(true);
54        mTFaces = typeBuilder.create();
55        mAFaces = Allocation.createTyped(RS, mTFaces);
56        s.set_aFaces(mAFaces);
57        typeBuilder.setFaces(false).setMipmaps(true);
58        mTLOD = typeBuilder.create();
59        mALOD = Allocation.createTyped(RS, mTLOD);
60        s.set_aLOD(mALOD);
61        typeBuilder.setFaces(true).setMipmaps(true);
62        mTFacesLOD = typeBuilder.create();
63        mAFacesLOD = Allocation.createTyped(RS, mTFacesLOD);
64        s.set_aFacesLOD(mAFacesLOD);
65
66        return;
67    }
68
69    public void run() {
70        RenderScript pRS = createRenderScript(true);
71        ScriptC_alloc s = new ScriptC_alloc(pRS);
72        initializeGlobals(pRS, s);
73        s.forEach_root(s.get_aRaw());
74        s.invoke_alloc_test();
75        pRS.finish();
76        T.destroy();
77        s.get_a().destroy();
78        mAFaces.destroy();
79        mALOD.destroy();
80        mAFacesLOD.destroy();
81        mTFaces.destroy();
82        mTLOD.destroy();
83        mTFacesLOD.destroy();
84        s.destroy();
85        pRS.destroy();
86    }
87}
88