1 /* 2 * Copyright (C) 2008 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; 18 19 20 import java.io.IOException; 21 import java.io.InputStream; 22 23 import android.content.res.Resources; 24 import android.os.Bundle; 25 import android.util.Config; 26 import android.util.Log; 27 28 import android.graphics.Bitmap; 29 import android.graphics.BitmapFactory; 30 31 /** 32 * @hide 33 * 34 **/ 35 public class Sampler extends BaseObj { 36 public enum Value { 37 NEAREST (0), 38 LINEAR (1), 39 LINEAR_MIP_LINEAR (2), 40 WRAP (3), 41 CLAMP (4); 42 43 int mID; 44 Value(int id) { 45 mID = id; 46 } 47 } 48 49 Sampler(int id, RenderScript rs) { 50 super(rs); 51 mID = id; 52 } 53 54 public static class Builder { 55 RenderScript mRS; 56 Value mMin; 57 Value mMag; 58 Value mWrapS; 59 Value mWrapT; 60 Value mWrapR; 61 62 public Builder(RenderScript rs) { 63 mRS = rs; 64 mMin = Value.NEAREST; 65 mMag = Value.NEAREST; 66 mWrapS = Value.WRAP; 67 mWrapT = Value.WRAP; 68 mWrapR = Value.WRAP; 69 } 70 71 public void setMin(Value v) { 72 if (v == Value.NEAREST || 73 v == Value.LINEAR || 74 v == Value.LINEAR_MIP_LINEAR) { 75 mMin = v; 76 } else { 77 throw new IllegalArgumentException("Invalid value"); 78 } 79 } 80 81 public void setMag(Value v) { 82 if (v == Value.NEAREST || v == Value.LINEAR) { 83 mMag = v; 84 } else { 85 throw new IllegalArgumentException("Invalid value"); 86 } 87 } 88 89 public void setWrapS(Value v) { 90 if (v == Value.WRAP || v == Value.CLAMP) { 91 mWrapS = v; 92 } else { 93 throw new IllegalArgumentException("Invalid value"); 94 } 95 } 96 97 public void setWrapT(Value v) { 98 if (v == Value.WRAP || v == Value.CLAMP) { 99 mWrapT = v; 100 } else { 101 throw new IllegalArgumentException("Invalid value"); 102 } 103 } 104 105 public void setWrapR(Value v) { 106 if (v == Value.WRAP || v == Value.CLAMP) { 107 mWrapR = v; 108 } else { 109 throw new IllegalArgumentException("Invalid value"); 110 } 111 } 112 113 static synchronized Sampler internalCreate(RenderScript rs, Builder b) { 114 rs.nSamplerBegin(); 115 rs.nSamplerSet(0, b.mMin.mID); 116 rs.nSamplerSet(1, b.mMag.mID); 117 rs.nSamplerSet(2, b.mWrapS.mID); 118 rs.nSamplerSet(3, b.mWrapT.mID); 119 rs.nSamplerSet(4, b.mWrapR.mID); 120 int id = rs.nSamplerCreate(); 121 return new Sampler(id, rs); 122 } 123 124 public Sampler create() { 125 mRS.validate(); 126 return internalCreate(mRS, this); 127 } 128 } 129 130 } 131 132