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