blob: 40ba7225f95ee0756300856d90bd766a5e60bfdc [file] [log] [blame]
Jason Sams0835d422009-08-04 17:58:23 -07001/*
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
17package android.renderscript;
18
19
20import java.io.IOException;
21import java.io.InputStream;
22
23import android.content.res.Resources;
24import android.os.Bundle;
25import android.util.Config;
26import android.util.Log;
27
28import android.graphics.Bitmap;
29import android.graphics.BitmapFactory;
30
31/**
32 * @hide
33 *
34 **/
35public 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
Jason Sams0835d422009-08-04 17:58:23 -070054 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) {
Jason Sams8bb41dd2009-12-16 15:59:59 -080072 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 }
Jason Sams0835d422009-08-04 17:58:23 -070079 }
80
81 public void setMag(Value v) {
Jason Sams8bb41dd2009-12-16 15:59:59 -080082 if (v == Value.NEAREST || v == Value.LINEAR) {
83 mMag = v;
84 } else {
85 throw new IllegalArgumentException("Invalid value");
86 }
Jason Sams0835d422009-08-04 17:58:23 -070087 }
88
89 public void setWrapS(Value v) {
Jason Sams8bb41dd2009-12-16 15:59:59 -080090 if (v == Value.WRAP || v == Value.CLAMP) {
91 mWrapS = v;
92 } else {
93 throw new IllegalArgumentException("Invalid value");
94 }
Jason Sams0835d422009-08-04 17:58:23 -070095 }
96
97 public void setWrapT(Value v) {
Jason Sams8bb41dd2009-12-16 15:59:59 -080098 if (v == Value.WRAP || v == Value.CLAMP) {
99 mWrapT = v;
100 } else {
101 throw new IllegalArgumentException("Invalid value");
102 }
Jason Sams0835d422009-08-04 17:58:23 -0700103 }
104
105 public void setWrapR(Value v) {
Jason Sams8bb41dd2009-12-16 15:59:59 -0800106 if (v == Value.WRAP || v == Value.CLAMP) {
107 mWrapR = v;
108 } else {
109 throw new IllegalArgumentException("Invalid value");
110 }
Jason Sams0835d422009-08-04 17:58:23 -0700111 }
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() {
Jason Sams771bebb2009-12-07 12:40:12 -0800125 mRS.validate();
Jason Sams0835d422009-08-04 17:58:23 -0700126 return internalCreate(mRS, this);
127 }
128 }
129
130}
131