1 /* 2 * Copyright (C) 2012 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 android.renderscript.cts; 18 19 import android.graphics.Bitmap; 20 import android.renderscript.Allocation; 21 import android.renderscript.Allocation.MipmapControl; 22 import android.renderscript.Element; 23 import android.renderscript.RSIllegalArgumentException; 24 import android.renderscript.Sampler; 25 import android.renderscript.Type; 26 import android.renderscript.Type.CubemapFace; 27 28 public class SampleTest extends RSBaseCompute { 29 30 ScriptC_sample mScript; 31 32 Allocation mAlloc_RGBA_1D; 33 Allocation mAlloc_RGBA_2D; 34 35 Allocation createAlloc(Type t) { 36 Allocation a = Allocation.createTyped(mRS, t, Allocation.MipmapControl.MIPMAP_FULL, 37 Allocation.USAGE_SCRIPT); 38 39 int[] tmp = new int[t.getCount()]; 40 int idx = 0; 41 int w = t.getY(); 42 if (w < 1) { 43 w = 1; 44 } 45 46 for (int ct = 0; ct < (8 * w); ct++) { 47 tmp[idx++] = 0x0000ffff; 48 } 49 w = (w + 1) >> 1; 50 for (int ct = 0; ct < (4 * w); ct++) { 51 tmp[idx++] = 0x00ff00ff; 52 } 53 w = (w + 1) >> 1; 54 for (int ct = 0; ct < (2 * w); ct++) { 55 tmp[idx++] = 0x00ffff00; 56 } 57 w = (w + 1) >> 1; 58 for (int ct = 0; ct < (1 * 1); ct++) { 59 tmp[idx++] = 0xffffff00; 60 } 61 a.copyFromUnchecked(tmp); 62 return a; 63 } 64 65 @Override 66 protected void setUp() throws Exception { 67 super.setUp(); 68 69 Element format = Element.RGBA_8888(mRS); 70 Type.Builder b = new Type.Builder(mRS, format); 71 b.setMipmaps(true); 72 mAlloc_RGBA_1D = createAlloc(b.setX(8).create()); 73 mAlloc_RGBA_2D = createAlloc(b.setX(8).setY(8).create()); 74 75 mScript = new ScriptC_sample(mRS); 76 77 mScript.set_gNearest(Sampler.CLAMP_NEAREST(mRS)); 78 mScript.set_gLinear(Sampler.CLAMP_LINEAR(mRS)); 79 80 Sampler.Builder sb = new Sampler.Builder(mRS); 81 sb.setMinification(Sampler.Value.LINEAR_MIP_NEAREST); 82 mScript.set_gMipNearest(sb.create()); 83 84 mScript.set_gMipLinear(Sampler.CLAMP_LINEAR_MIP_LINEAR(mRS)); 85 } 86 87 @Override 88 protected void tearDown() throws Exception { 89 mAlloc_RGBA_1D.destroy(); 90 mAlloc_RGBA_2D.destroy(); 91 mScript.destroy(); 92 super.tearDown(); 93 } 94 95 public void testNearest() { 96 mScript.invoke_test_RGBA(mAlloc_RGBA_1D, mAlloc_RGBA_2D); 97 mRS.finish(); 98 waitForMessage(); 99 checkForErrors(); 100 } 101 } 102 103 104