blob: e24984221b76913b9ee07e170a2a428d3cc280ee [file] [log] [blame]
Jason Sams22534172009-08-04 16:58:20 -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 android.util.Config;
21import android.util.Log;
22
23
24/**
25 * @hide
26 *
27 **/
28public class ProgramStore extends BaseObj {
29 public enum DepthFunc {
30 ALWAYS (0),
31 LESS (1),
32 LEQUAL (2),
33 GREATER (3),
34 GEQUAL (4),
35 EQUAL (5),
36 NOTEQUAL (6);
37
38 int mID;
39 DepthFunc(int id) {
40 mID = id;
41 }
42 }
43
44 public enum BlendSrcFunc {
45 ZERO (0),
46 ONE (1),
47 DST_COLOR (2),
48 ONE_MINUS_DST_COLOR (3),
49 SRC_ALPHA (4),
50 ONE_MINUS_SRC_ALPHA (5),
51 DST_ALPHA (6),
Jason Samseab4c752009-10-28 17:40:13 -070052 ONE_MINUS_DST_ALPHA (7),
Jason Sams22534172009-08-04 16:58:20 -070053 SRC_ALPHA_SATURATE (8);
54
55 int mID;
56 BlendSrcFunc(int id) {
57 mID = id;
58 }
59 }
60
61 public enum BlendDstFunc {
62 ZERO (0),
63 ONE (1),
64 SRC_COLOR (2),
65 ONE_MINUS_SRC_COLOR (3),
66 SRC_ALPHA (4),
67 ONE_MINUS_SRC_ALPHA (5),
68 DST_ALPHA (6),
Jason Samseab4c752009-10-28 17:40:13 -070069 ONE_MINUS_DST_ALPHA (7);
Jason Sams22534172009-08-04 16:58:20 -070070
71 int mID;
72 BlendDstFunc(int id) {
73 mID = id;
74 }
75 }
76
77
78 ProgramStore(int id, RenderScript rs) {
Alex Sakhartchouk0de94442010-08-11 14:41:28 -070079 super(id, rs);
Jason Sams22534172009-08-04 16:58:20 -070080 }
81
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -070082 public static ProgramStore BlendNone_DepthTest(RenderScript rs) {
83 if(rs.mProgramStore_BlendNone_DepthTest == null) {
84 ProgramStore.Builder builder = new ProgramStore.Builder(rs);
85 builder.setDepthFunc(ProgramStore.DepthFunc.LESS);
86 builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ZERO);
87 builder.setDitherEnable(false);
88 builder.setDepthMask(true);
89 rs.mProgramStore_BlendNone_DepthTest = builder.create();
90 }
91 return rs.mProgramStore_BlendNone_DepthTest;
92 }
93 public static ProgramStore BlendNone_DepthNoDepth(RenderScript rs) {
94 if(rs.mProgramStore_BlendNone_DepthNoDepth == null) {
95 ProgramStore.Builder builder = new ProgramStore.Builder(rs);
96 builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
97 builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ZERO);
98 builder.setDitherEnable(false);
99 builder.setDepthMask(false);
100 rs.mProgramStore_BlendNone_DepthNoDepth = builder.create();
101 }
102 return rs.mProgramStore_BlendNone_DepthNoDepth;
103 }
104 public static ProgramStore BlendNone_DepthNoTest(RenderScript rs) {
105 if(rs.mProgramStore_BlendNone_DepthNoTest == null) {
106 ProgramStore.Builder builder = new ProgramStore.Builder(rs);
107 builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
108 builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ZERO);
109 builder.setDitherEnable(false);
110 builder.setDepthMask(true);
111 rs.mProgramStore_BlendNone_DepthNoTest = builder.create();
112 }
113 return rs.mProgramStore_BlendNone_DepthNoTest;
114 }
115 public static ProgramStore BlendNone_DepthNoWrite(RenderScript rs) {
116 if(rs.mProgramStore_BlendNone_DepthNoWrite == null) {
117 ProgramStore.Builder builder = new ProgramStore.Builder(rs);
118 builder.setDepthFunc(ProgramStore.DepthFunc.LESS);
119 builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ZERO);
120 builder.setDitherEnable(false);
121 builder.setDepthMask(false);
122 rs.mProgramStore_BlendNone_DepthNoWrite = builder.create();
123 }
124 return rs.mProgramStore_BlendNone_DepthNoWrite;
125 }
Jason Sams22534172009-08-04 16:58:20 -0700126
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700127 public static ProgramStore BlendAlpha_DepthTest(RenderScript rs) {
128 if(rs.mProgramStore_BlendAlpha_DepthTest == null) {
129 ProgramStore.Builder builder = new ProgramStore.Builder(rs);
130 builder.setDepthFunc(ProgramStore.DepthFunc.LESS);
131 builder.setBlendFunc(BlendSrcFunc.SRC_ALPHA, BlendDstFunc.ONE_MINUS_SRC_ALPHA);
132 builder.setDitherEnable(false);
133 builder.setDepthMask(true);
134 rs.mProgramStore_BlendAlpha_DepthTest = builder.create();
135 }
136 return rs.mProgramStore_BlendAlpha_DepthTest;
137 }
138 public static ProgramStore BlendAlpha_DepthNoDepth(RenderScript rs) {
139 if(rs.mProgramStore_BlendAlpha_DepthNoDepth == null) {
140 ProgramStore.Builder builder = new ProgramStore.Builder(rs);
141 builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
142 builder.setBlendFunc(BlendSrcFunc.SRC_ALPHA, BlendDstFunc.ONE_MINUS_SRC_ALPHA);
143 builder.setDitherEnable(false);
144 builder.setDepthMask(false);
145 rs.mProgramStore_BlendAlpha_DepthNoDepth = builder.create();
146 }
147 return rs.mProgramStore_BlendAlpha_DepthNoDepth;
148 }
149 public static ProgramStore BlendAlpha_DepthNoTest(RenderScript rs) {
150 if(rs.mProgramStore_BlendAlpha_DepthNoTest == null) {
151 ProgramStore.Builder builder = new ProgramStore.Builder(rs);
152 builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
153 builder.setBlendFunc(BlendSrcFunc.SRC_ALPHA, BlendDstFunc.ONE_MINUS_SRC_ALPHA);
154 builder.setDitherEnable(false);
155 builder.setDepthMask(true);
156 rs.mProgramStore_BlendAlpha_DepthNoTest = builder.create();
157 }
158 return rs.mProgramStore_BlendAlpha_DepthNoTest;
159 }
160 public static ProgramStore BlendAlpha_DepthNoWrite(RenderScript rs) {
161 if(rs.mProgramStore_BlendAlpha_DepthNoWrite == null) {
162 ProgramStore.Builder builder = new ProgramStore.Builder(rs);
163 builder.setDepthFunc(ProgramStore.DepthFunc.LESS);
164 builder.setBlendFunc(BlendSrcFunc.SRC_ALPHA, BlendDstFunc.ONE_MINUS_SRC_ALPHA);
165 builder.setDitherEnable(false);
166 builder.setDepthMask(false);
167 rs.mProgramStore_BlendAlpha_DepthNoWrite = builder.create();
168 }
169 return rs.mProgramStore_BlendAlpha_DepthNoWrite;
170 }
171
172 public static ProgramStore BlendAdd_DepthTest(RenderScript rs) {
173 if(rs.mProgramStore_BlendAdd_DepthTest == null) {
174 ProgramStore.Builder builder = new ProgramStore.Builder(rs);
175 builder.setDepthFunc(ProgramStore.DepthFunc.LESS);
176 builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ONE);
177 builder.setDitherEnable(false);
178 builder.setDepthMask(true);
179 rs.mProgramStore_BlendAdd_DepthTest = builder.create();
180 }
181 return rs.mProgramStore_BlendAdd_DepthTest;
182 }
183 public static ProgramStore BlendAdd_DepthNoDepth(RenderScript rs) {
184 if(rs.mProgramStore_BlendAdd_DepthNoDepth == null) {
185 ProgramStore.Builder builder = new ProgramStore.Builder(rs);
186 builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
187 builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ONE);
188 builder.setDitherEnable(false);
189 builder.setDepthMask(false);
190 rs.mProgramStore_BlendAdd_DepthNoDepth = builder.create();
191 }
192 return rs.mProgramStore_BlendAdd_DepthNoDepth;
193 }
194 public static ProgramStore BlendAdd_DepthNoTest(RenderScript rs) {
195 if(rs.mProgramStore_BlendAdd_DepthNoTest == null) {
196 ProgramStore.Builder builder = new ProgramStore.Builder(rs);
197 builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
198 builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ONE);
199 builder.setDitherEnable(false);
200 builder.setDepthMask(true);
201 rs.mProgramStore_BlendAdd_DepthNoDepth = builder.create();
202 }
203 return rs.mProgramStore_BlendAdd_DepthNoTest;
204 }
205 public static ProgramStore BlendAdd_DepthNoWrite(RenderScript rs) {
206 if(rs.mProgramStore_BlendAdd_DepthNoWrite == null) {
207 ProgramStore.Builder builder = new ProgramStore.Builder(rs);
208 builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
209 builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ONE);
210 builder.setDitherEnable(false);
211 builder.setDepthMask(false);
212 rs.mProgramStore_BlendAdd_DepthNoWrite = builder.create();
213 }
214 return rs.mProgramStore_BlendAdd_DepthNoWrite;
215 }
Jason Sams22534172009-08-04 16:58:20 -0700216
217 public static class Builder {
218 RenderScript mRS;
219 Element mIn;
220 Element mOut;
221 DepthFunc mDepthFunc;
222 boolean mDepthMask;
223 boolean mColorMaskR;
224 boolean mColorMaskG;
225 boolean mColorMaskB;
226 boolean mColorMaskA;
227 BlendSrcFunc mBlendSrc;
228 BlendDstFunc mBlendDst;
229 boolean mDither;
230
231
232
233 public Builder(RenderScript rs, Element in, Element out) {
234 mRS = rs;
235 mIn = in;
236 mOut = out;
237 mDepthFunc = DepthFunc.ALWAYS;
238 mDepthMask = false;
239 mColorMaskR = true;
240 mColorMaskG = true;
241 mColorMaskB = true;
242 mColorMaskA = true;
243 mBlendSrc = BlendSrcFunc.ONE;
244 mBlendDst = BlendDstFunc.ZERO;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700245 }
Jason Sams22534172009-08-04 16:58:20 -0700246
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700247 public Builder(RenderScript rs) {
248 mRS = rs;
249 mIn = null;
250 mOut = null;
251 mDepthFunc = DepthFunc.ALWAYS;
252 mDepthMask = false;
253 mColorMaskR = true;
254 mColorMaskG = true;
255 mColorMaskB = true;
256 mColorMaskA = true;
257 mBlendSrc = BlendSrcFunc.ONE;
258 mBlendDst = BlendDstFunc.ZERO;
Jason Sams22534172009-08-04 16:58:20 -0700259 }
260
Jim Shuma288c8712010-07-07 14:24:21 -0700261 public Builder setDepthFunc(DepthFunc func) {
Jason Sams22534172009-08-04 16:58:20 -0700262 mDepthFunc = func;
Jim Shuma288c8712010-07-07 14:24:21 -0700263 return this;
Jason Sams22534172009-08-04 16:58:20 -0700264 }
265
Jim Shuma288c8712010-07-07 14:24:21 -0700266 public Builder setDepthMask(boolean enable) {
Jason Sams22534172009-08-04 16:58:20 -0700267 mDepthMask = enable;
Jim Shuma288c8712010-07-07 14:24:21 -0700268 return this;
Jason Sams22534172009-08-04 16:58:20 -0700269 }
270
Jim Shuma288c8712010-07-07 14:24:21 -0700271 public Builder setColorMask(boolean r, boolean g, boolean b, boolean a) {
Jason Sams22534172009-08-04 16:58:20 -0700272 mColorMaskR = r;
273 mColorMaskG = g;
274 mColorMaskB = b;
275 mColorMaskA = a;
Jim Shuma288c8712010-07-07 14:24:21 -0700276 return this;
Jason Sams22534172009-08-04 16:58:20 -0700277 }
278
Jim Shuma288c8712010-07-07 14:24:21 -0700279 public Builder setBlendFunc(BlendSrcFunc src, BlendDstFunc dst) {
Jason Sams22534172009-08-04 16:58:20 -0700280 mBlendSrc = src;
281 mBlendDst = dst;
Jim Shuma288c8712010-07-07 14:24:21 -0700282 return this;
Jason Sams22534172009-08-04 16:58:20 -0700283 }
284
Jim Shuma288c8712010-07-07 14:24:21 -0700285 public Builder setDitherEnable(boolean enable) {
Jason Sams22534172009-08-04 16:58:20 -0700286 mDither = enable;
Jim Shuma288c8712010-07-07 14:24:21 -0700287 return this;
Jason Sams22534172009-08-04 16:58:20 -0700288 }
289
290 static synchronized ProgramStore internalCreate(RenderScript rs, Builder b) {
291 int inID = 0;
292 int outID = 0;
293 if (b.mIn != null) {
294 inID = b.mIn.mID;
295 }
296 if (b.mOut != null) {
297 outID = b.mOut.mID;
298 }
Jason Sams54db59c2010-05-13 18:30:11 -0700299 rs.nProgramStoreBegin(inID, outID);
300 rs.nProgramStoreDepthFunc(b.mDepthFunc.mID);
301 rs.nProgramStoreDepthMask(b.mDepthMask);
302 rs.nProgramStoreColorMask(b.mColorMaskR,
Jason Sams22534172009-08-04 16:58:20 -0700303 b.mColorMaskG,
304 b.mColorMaskB,
305 b.mColorMaskA);
Jason Sams54db59c2010-05-13 18:30:11 -0700306 rs.nProgramStoreBlendFunc(b.mBlendSrc.mID, b.mBlendDst.mID);
307 rs.nProgramStoreDither(b.mDither);
Jason Sams22534172009-08-04 16:58:20 -0700308
Jason Sams54db59c2010-05-13 18:30:11 -0700309 int id = rs.nProgramStoreCreate();
Jason Sams22534172009-08-04 16:58:20 -0700310 return new ProgramStore(id, rs);
311 }
312
313 public ProgramStore create() {
Jason Sams771bebb2009-12-07 12:40:12 -0800314 mRS.validate();
Jason Sams22534172009-08-04 16:58:20 -0700315 return internalCreate(mRS, this);
316 }
317 }
318
319}
320
321
322
323