Home | History | Annotate | Download | only in unittest
      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 
     17 package com.android.rs.unittest;
     18 
     19 import android.content.Context;
     20 import android.renderscript.RenderScript;
     21 import android.renderscript.Sampler;
     22 
     23 public class UT_sampler extends UnitTest {
     24     Sampler minification;
     25     Sampler magnification;
     26     Sampler wrapS;
     27     Sampler wrapT;
     28     Sampler anisotropy;
     29 
     30     public UT_sampler(Context ctx) {
     31         super("Sampler", ctx);
     32     }
     33 
     34     private Sampler.Builder getDefaultBuilder(RenderScript RS) {
     35         Sampler.Builder b = new Sampler.Builder(RS);
     36         b.setMinification(Sampler.Value.NEAREST);
     37         b.setMagnification(Sampler.Value.NEAREST);
     38         b.setWrapS(Sampler.Value.CLAMP);
     39         b.setWrapT(Sampler.Value.CLAMP);
     40         b.setAnisotropy(1.0f);
     41         return b;
     42     }
     43 
     44     private void initializeGlobals(RenderScript RS, ScriptC_sampler s) {
     45         Sampler.Builder b = getDefaultBuilder(RS);
     46         b.setMinification(Sampler.Value.LINEAR_MIP_LINEAR);
     47         minification = b.create();
     48 
     49         b = getDefaultBuilder(RS);
     50         b.setMagnification(Sampler.Value.LINEAR);
     51         magnification = b.create();
     52 
     53         b = getDefaultBuilder(RS);
     54         b.setWrapS(Sampler.Value.WRAP);
     55         wrapS = b.create();
     56 
     57         b = getDefaultBuilder(RS);
     58         b.setWrapT(Sampler.Value.WRAP);
     59         wrapT = b.create();
     60 
     61         b = getDefaultBuilder(RS);
     62         b.setAnisotropy(8.0f);
     63         anisotropy = b.create();
     64 
     65         s.set_minification(minification);
     66         s.set_magnification(magnification);
     67         s.set_wrapS(wrapS);
     68         s.set_wrapT(wrapT);
     69         s.set_anisotropy(anisotropy);
     70     }
     71 
     72     private void testScriptSide(RenderScript pRS) {
     73         ScriptC_sampler s = new ScriptC_sampler(pRS);
     74         initializeGlobals(pRS, s);
     75         s.invoke_sampler_test();
     76         pRS.finish();
     77         s.destroy();
     78     }
     79 
     80     private void testJavaSide(RenderScript pRS) {
     81         _RS_ASSERT("minification.getMagnification() == Sampler.Value.NEAREST",
     82                 minification.getMagnification() == Sampler.Value.NEAREST);
     83         _RS_ASSERT("minification.getMinification() == Sampler.Value.LINEAR_MIP_LINEAR",
     84                 minification.getMinification() == Sampler.Value.LINEAR_MIP_LINEAR);
     85         _RS_ASSERT("minification.getWrapS() == Sampler.Value.CLAMP",
     86                 minification.getWrapS() == Sampler.Value.CLAMP);
     87         _RS_ASSERT("minification.getWrapT() == Sampler.Value.CLAMP",
     88                 minification.getWrapT() == Sampler.Value.CLAMP);
     89         _RS_ASSERT("minification.getAnisotropy() == 1.0f",
     90                 minification.getAnisotropy() == 1.0f);
     91 
     92         _RS_ASSERT("magnification.getMagnification() == Sampler.Value.LINEAR",
     93                 magnification.getMagnification() == Sampler.Value.LINEAR);
     94         _RS_ASSERT("magnification.getMinification() == Sampler.Value.NEAREST",
     95                 magnification.getMinification() == Sampler.Value.NEAREST);
     96         _RS_ASSERT("magnification.getWrapS() == Sampler.Value.CLAMP",
     97                 magnification.getWrapS() == Sampler.Value.CLAMP);
     98         _RS_ASSERT("magnification.getWrapT() == Sampler.Value.CLAMP",
     99                 magnification.getWrapT() == Sampler.Value.CLAMP);
    100         _RS_ASSERT("magnification.getAnisotropy() == 1.0f",
    101                 magnification.getAnisotropy() == 1.0f);
    102 
    103         _RS_ASSERT("wrapS.getMagnification() == Sampler.Value.NEAREST",
    104                 wrapS.getMagnification() == Sampler.Value.NEAREST);
    105         _RS_ASSERT("wrapS.getMinification() == Sampler.Value.NEAREST",
    106                 wrapS.getMinification() == Sampler.Value.NEAREST);
    107         _RS_ASSERT("wrapS.getWrapS() == Sampler.Value.WRAP",
    108                 wrapS.getWrapS() == Sampler.Value.WRAP);
    109         _RS_ASSERT("wrapS.getWrapT() == Sampler.Value.CLAMP",
    110                 wrapS.getWrapT() == Sampler.Value.CLAMP);
    111         _RS_ASSERT("wrapS.getAnisotropy() == 1.0f",
    112                 wrapS.getAnisotropy() == 1.0f);
    113 
    114         _RS_ASSERT("wrapT.getMagnification() == Sampler.Value.NEAREST",
    115                 wrapT.getMagnification() == Sampler.Value.NEAREST);
    116         _RS_ASSERT("wrapT.getMinification() == Sampler.Value.NEAREST",
    117                 wrapT.getMinification() == Sampler.Value.NEAREST);
    118         _RS_ASSERT("wrapT.getWrapS() == Sampler.Value.CLAMP",
    119                 wrapT.getWrapS() == Sampler.Value.CLAMP);
    120         _RS_ASSERT("wrapT.getWrapT() == Sampler.Value.WRAP",
    121                 wrapT.getWrapT() == Sampler.Value.WRAP);
    122         _RS_ASSERT("wrapT.getAnisotropy() == 1.0f",
    123                 wrapT.getAnisotropy() == 1.0f);
    124 
    125         _RS_ASSERT("anisotropy.getMagnification() == Sampler.Value.NEAREST",
    126                 anisotropy.getMagnification() == Sampler.Value.NEAREST);
    127         _RS_ASSERT("anisotropy.getMinification() == Sampler.Value.NEAREST",
    128                 anisotropy.getMinification() == Sampler.Value.NEAREST);
    129         _RS_ASSERT("anisotropy.getWrapS() == Sampler.Value.CLAMP",
    130                 anisotropy.getWrapS() == Sampler.Value.CLAMP);
    131         _RS_ASSERT("anisotropy.getWrapT() == Sampler.Value.CLAMP",
    132                 anisotropy.getWrapT() == Sampler.Value.CLAMP);
    133         _RS_ASSERT("anisotropy.getAnisotropy() == 1.0f",
    134                 anisotropy.getAnisotropy() == 8.0f);
    135     }
    136 
    137     public void run() {
    138         RenderScript pRS = createRenderScript(true);
    139         testScriptSide(pRS);
    140         testJavaSide(pRS);
    141         passTest();
    142         pRS.destroy();
    143     }
    144 }
    145