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), |
| 52 | ONE_MINUS_DST_ALPA (7), |
| 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), |
| 69 | ONE_MINUS_DST_ALPA (7); |
| 70 | |
| 71 | int mID; |
| 72 | BlendDstFunc(int id) { |
| 73 | mID = id; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | |
| 78 | ProgramStore(int id, RenderScript rs) { |
| 79 | super(rs); |
| 80 | mID = id; |
| 81 | } |
| 82 | |
| 83 | public void destroy() { |
| 84 | mRS.nProgramFragmentStoreDestroy(mID); |
| 85 | mID = 0; |
| 86 | } |
| 87 | |
| 88 | |
| 89 | |
| 90 | public static class Builder { |
| 91 | RenderScript mRS; |
| 92 | Element mIn; |
| 93 | Element mOut; |
| 94 | DepthFunc mDepthFunc; |
| 95 | boolean mDepthMask; |
| 96 | boolean mColorMaskR; |
| 97 | boolean mColorMaskG; |
| 98 | boolean mColorMaskB; |
| 99 | boolean mColorMaskA; |
| 100 | BlendSrcFunc mBlendSrc; |
| 101 | BlendDstFunc mBlendDst; |
| 102 | boolean mDither; |
| 103 | |
| 104 | |
| 105 | |
| 106 | public Builder(RenderScript rs, Element in, Element out) { |
| 107 | mRS = rs; |
| 108 | mIn = in; |
| 109 | mOut = out; |
| 110 | mDepthFunc = DepthFunc.ALWAYS; |
| 111 | mDepthMask = false; |
| 112 | mColorMaskR = true; |
| 113 | mColorMaskG = true; |
| 114 | mColorMaskB = true; |
| 115 | mColorMaskA = true; |
| 116 | mBlendSrc = BlendSrcFunc.ONE; |
| 117 | mBlendDst = BlendDstFunc.ZERO; |
| 118 | |
| 119 | |
| 120 | } |
| 121 | |
| 122 | public void setDepthFunc(DepthFunc func) { |
| 123 | mDepthFunc = func; |
| 124 | } |
| 125 | |
| 126 | public void setDepthMask(boolean enable) { |
| 127 | mDepthMask = enable; |
| 128 | } |
| 129 | |
| 130 | public void setColorMask(boolean r, boolean g, boolean b, boolean a) { |
| 131 | mColorMaskR = r; |
| 132 | mColorMaskG = g; |
| 133 | mColorMaskB = b; |
| 134 | mColorMaskA = a; |
| 135 | } |
| 136 | |
| 137 | public void setBlendFunc(BlendSrcFunc src, BlendDstFunc dst) { |
| 138 | mBlendSrc = src; |
| 139 | mBlendDst = dst; |
| 140 | } |
| 141 | |
| 142 | public void setDitherEnable(boolean enable) { |
| 143 | mDither = enable; |
| 144 | } |
| 145 | |
| 146 | static synchronized ProgramStore internalCreate(RenderScript rs, Builder b) { |
| 147 | int inID = 0; |
| 148 | int outID = 0; |
| 149 | if (b.mIn != null) { |
| 150 | inID = b.mIn.mID; |
| 151 | } |
| 152 | if (b.mOut != null) { |
| 153 | outID = b.mOut.mID; |
| 154 | } |
| 155 | rs.nProgramFragmentStoreBegin(inID, outID); |
| 156 | rs.nProgramFragmentStoreDepthFunc(b.mDepthFunc.mID); |
| 157 | rs.nProgramFragmentStoreDepthMask(b.mDepthMask); |
| 158 | rs.nProgramFragmentStoreColorMask(b.mColorMaskR, |
| 159 | b.mColorMaskG, |
| 160 | b.mColorMaskB, |
| 161 | b.mColorMaskA); |
| 162 | rs.nProgramFragmentStoreBlendFunc(b.mBlendSrc.mID, b.mBlendDst.mID); |
| 163 | rs.nProgramFragmentStoreDither(b.mDither); |
| 164 | |
| 165 | int id = rs.nProgramFragmentStoreCreate(); |
| 166 | return new ProgramStore(id, rs); |
| 167 | } |
| 168 | |
| 169 | public ProgramStore create() { |
| 170 | return internalCreate(mRS, this); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | } |
| 175 | |
| 176 | |
| 177 | |
| 178 | |