1/* 2 * Copyright (C) 2011 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 com.android.rs.test; 18 19import android.content.Context; 20import android.content.res.Resources; 21import android.renderscript.*; 22import android.renderscript.ProgramStore.BlendDstFunc; 23import android.renderscript.ProgramStore.BlendSrcFunc; 24import android.renderscript.ProgramStore.Builder; 25import android.renderscript.ProgramStore.DepthFunc; 26 27public class UT_program_store extends UnitTest { 28 private Resources mRes; 29 30 ProgramStore ditherEnable; 31 ProgramStore colorRWriteEnable; 32 ProgramStore colorGWriteEnable; 33 ProgramStore colorBWriteEnable; 34 ProgramStore colorAWriteEnable; 35 ProgramStore blendSrc; 36 ProgramStore blendDst; 37 ProgramStore depthWriteEnable; 38 ProgramStore depthFunc; 39 40 protected UT_program_store(RSTestCore rstc, Resources res, Context ctx) { 41 super(rstc, "ProgramStore", ctx); 42 mRes = res; 43 } 44 45 private ProgramStore.Builder getDefaultBuilder(RenderScript RS) { 46 ProgramStore.Builder b = new ProgramStore.Builder(RS); 47 b.setBlendFunc(ProgramStore.BlendSrcFunc.ZERO, ProgramStore.BlendDstFunc.ZERO); 48 b.setColorMaskEnabled(false, false, false, false); 49 b.setDepthFunc(ProgramStore.DepthFunc.ALWAYS); 50 b.setDepthMaskEnabled(false); 51 b.setDitherEnabled(false); 52 return b; 53 } 54 55 private void initializeGlobals(RenderScript RS, ScriptC_program_store s) { 56 ProgramStore.Builder b = getDefaultBuilder(RS); 57 ditherEnable = b.setDitherEnabled(true).create(); 58 59 b = getDefaultBuilder(RS); 60 colorRWriteEnable = b.setColorMaskEnabled(true, false, false, false).create(); 61 62 b = getDefaultBuilder(RS); 63 colorGWriteEnable = b.setColorMaskEnabled(false, true, false, false).create(); 64 65 b = getDefaultBuilder(RS); 66 colorBWriteEnable = b.setColorMaskEnabled(false, false, true, false).create(); 67 68 b = getDefaultBuilder(RS); 69 colorAWriteEnable = b.setColorMaskEnabled(false, false, false, true).create(); 70 71 b = getDefaultBuilder(RS); 72 blendSrc = b.setBlendFunc(ProgramStore.BlendSrcFunc.DST_COLOR, 73 ProgramStore.BlendDstFunc.ZERO).create(); 74 75 b = getDefaultBuilder(RS); 76 blendDst = b.setBlendFunc(ProgramStore.BlendSrcFunc.ZERO, 77 ProgramStore.BlendDstFunc.DST_ALPHA).create(); 78 79 b = getDefaultBuilder(RS); 80 depthWriteEnable = b.setDepthMaskEnabled(true).create(); 81 82 b = getDefaultBuilder(RS); 83 depthFunc = b.setDepthFunc(ProgramStore.DepthFunc.GREATER).create(); 84 85 s.set_ditherEnable(ditherEnable); 86 s.set_colorRWriteEnable(colorRWriteEnable); 87 s.set_colorGWriteEnable(colorGWriteEnable); 88 s.set_colorBWriteEnable(colorBWriteEnable); 89 s.set_colorAWriteEnable(colorAWriteEnable); 90 s.set_blendSrc(blendSrc); 91 s.set_blendDst(blendDst); 92 s.set_depthWriteEnable(depthWriteEnable); 93 s.set_depthFunc(depthFunc); 94 } 95 96 private void testScriptSide(RenderScript pRS) { 97 ScriptC_program_store s = new ScriptC_program_store(pRS); 98 pRS.setMessageHandler(mRsMessage); 99 initializeGlobals(pRS, s); 100 s.invoke_program_store_test(); 101 pRS.finish(); 102 waitForMessage(); 103 } 104 105 void checkObject(ProgramStore ps, 106 boolean depthMask, 107 DepthFunc df, 108 BlendSrcFunc bsf, 109 BlendDstFunc bdf, 110 boolean R, 111 boolean G, 112 boolean B, 113 boolean A, 114 boolean dither) { 115 _RS_ASSERT("ps.isDepthMaskEnabled() == depthMask", ps.isDepthMaskEnabled() == depthMask); 116 _RS_ASSERT("ps.getDepthFunc() == df", ps.getDepthFunc() == df); 117 _RS_ASSERT("ps.getBlendSrcFunc() == bsf", ps.getBlendSrcFunc() == bsf); 118 _RS_ASSERT("ps.getBlendDstFunc() == bdf", ps.getBlendDstFunc() == bdf); 119 _RS_ASSERT("ps.isColorMaskRedEnabled() == R", ps.isColorMaskRedEnabled() == R); 120 _RS_ASSERT("ps.isColorMaskGreenEnabled() == G", ps.isColorMaskGreenEnabled() == G); 121 _RS_ASSERT("ps.isColorMaskBlueEnabled () == B", ps.isColorMaskBlueEnabled () == B); 122 _RS_ASSERT("ps.isColorMaskAlphaEnabled() == A", ps.isColorMaskAlphaEnabled() == A); 123 _RS_ASSERT("ps.isDitherEnabled() == dither", ps.isDitherEnabled() == dither); 124 } 125 126 void varyBuilderColorAndDither(ProgramStore.Builder pb, 127 boolean depthMask, 128 DepthFunc df, 129 BlendSrcFunc bsf, 130 BlendDstFunc bdf) { 131 for (int r = 0; r <= 1; r++) { 132 boolean isR = (r == 1); 133 for (int g = 0; g <= 1; g++) { 134 boolean isG = (g == 1); 135 for (int b = 0; b <= 1; b++) { 136 boolean isB = (b == 1); 137 for (int a = 0; a <= 1; a++) { 138 boolean isA = (a == 1); 139 for (int dither = 0; dither <= 1; dither++) { 140 boolean isDither = (dither == 1); 141 pb.setDitherEnabled(isDither); 142 pb.setColorMaskEnabled(isR, isG, isB, isA); 143 ProgramStore ps = pb.create(); 144 checkObject(ps, depthMask, df, bsf, bdf, isR, isG, isB, isA, isDither); 145 } 146 } 147 } 148 } 149 } 150 } 151 152 public void testJavaSide(RenderScript RS) { 153 for (int depth = 0; depth <= 1; depth++) { 154 boolean depthMask = (depth == 1); 155 for (DepthFunc df : DepthFunc.values()) { 156 for (BlendSrcFunc bsf : BlendSrcFunc.values()) { 157 for (BlendDstFunc bdf : BlendDstFunc.values()) { 158 ProgramStore.Builder b = new ProgramStore.Builder(RS); 159 b.setDepthFunc(df); 160 b.setDepthMaskEnabled(depthMask); 161 b.setBlendFunc(bsf, bdf); 162 varyBuilderColorAndDither(b, depthMask, df, bsf, bdf); 163 } 164 } 165 } 166 } 167 } 168 169 public void run() { 170 RenderScript pRS = RenderScript.create(mCtx); 171 testJavaSide(pRS); 172 testScriptSide(pRS); 173 pRS.destroy(); 174 } 175} 176