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