Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 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 android.util.Config; |
| 21 | import android.util.Log; |
| 22 | |
| 23 | |
| 24 | /** |
| 25 | * @hide |
| 26 | * |
| 27 | **/ |
| 28 | public 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 Sams | eab4c75 | 2009-10-28 17:40:13 -0700 | [diff] [blame] | 52 | ONE_MINUS_DST_ALPHA (7), |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 53 | 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 Sams | eab4c75 | 2009-10-28 17:40:13 -0700 | [diff] [blame] | 69 | ONE_MINUS_DST_ALPHA (7); |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 70 | |
| 71 | int mID; |
| 72 | BlendDstFunc(int id) { |
| 73 | mID = id; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | |
| 78 | ProgramStore(int id, RenderScript rs) { |
Alex Sakhartchouk | 0de9444 | 2010-08-11 14:41:28 -0700 | [diff] [blame] | 79 | super(id, rs); |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame^] | 82 | 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 Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 126 | |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame^] | 127 | 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 Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 216 | |
| 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 Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame^] | 245 | } |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 246 | |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame^] | 247 | 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 Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Jim Shuma | 288c871 | 2010-07-07 14:24:21 -0700 | [diff] [blame] | 261 | public Builder setDepthFunc(DepthFunc func) { |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 262 | mDepthFunc = func; |
Jim Shuma | 288c871 | 2010-07-07 14:24:21 -0700 | [diff] [blame] | 263 | return this; |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Jim Shuma | 288c871 | 2010-07-07 14:24:21 -0700 | [diff] [blame] | 266 | public Builder setDepthMask(boolean enable) { |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 267 | mDepthMask = enable; |
Jim Shuma | 288c871 | 2010-07-07 14:24:21 -0700 | [diff] [blame] | 268 | return this; |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 269 | } |
| 270 | |
Jim Shuma | 288c871 | 2010-07-07 14:24:21 -0700 | [diff] [blame] | 271 | public Builder setColorMask(boolean r, boolean g, boolean b, boolean a) { |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 272 | mColorMaskR = r; |
| 273 | mColorMaskG = g; |
| 274 | mColorMaskB = b; |
| 275 | mColorMaskA = a; |
Jim Shuma | 288c871 | 2010-07-07 14:24:21 -0700 | [diff] [blame] | 276 | return this; |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 277 | } |
| 278 | |
Jim Shuma | 288c871 | 2010-07-07 14:24:21 -0700 | [diff] [blame] | 279 | public Builder setBlendFunc(BlendSrcFunc src, BlendDstFunc dst) { |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 280 | mBlendSrc = src; |
| 281 | mBlendDst = dst; |
Jim Shuma | 288c871 | 2010-07-07 14:24:21 -0700 | [diff] [blame] | 282 | return this; |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Jim Shuma | 288c871 | 2010-07-07 14:24:21 -0700 | [diff] [blame] | 285 | public Builder setDitherEnable(boolean enable) { |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 286 | mDither = enable; |
Jim Shuma | 288c871 | 2010-07-07 14:24:21 -0700 | [diff] [blame] | 287 | return this; |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 288 | } |
| 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 Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 299 | rs.nProgramStoreBegin(inID, outID); |
| 300 | rs.nProgramStoreDepthFunc(b.mDepthFunc.mID); |
| 301 | rs.nProgramStoreDepthMask(b.mDepthMask); |
| 302 | rs.nProgramStoreColorMask(b.mColorMaskR, |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 303 | b.mColorMaskG, |
| 304 | b.mColorMaskB, |
| 305 | b.mColorMaskA); |
Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 306 | rs.nProgramStoreBlendFunc(b.mBlendSrc.mID, b.mBlendDst.mID); |
| 307 | rs.nProgramStoreDither(b.mDither); |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 308 | |
Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 309 | int id = rs.nProgramStoreCreate(); |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 310 | return new ProgramStore(id, rs); |
| 311 | } |
| 312 | |
| 313 | public ProgramStore create() { |
Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 314 | mRS.validate(); |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 315 | return internalCreate(mRS, this); |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | } |
| 320 | |
| 321 | |
| 322 | |
| 323 | |