Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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 | #include "rsContext.h" |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 18 | #include "rsProgramStore.h" |
Jason Sams | 4b962e5 | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 19 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 20 | using namespace android; |
| 21 | using namespace android::renderscript; |
| 22 | |
| 23 | |
Jason Sams | 331bf9b | 2011-04-06 11:23:54 -0700 | [diff] [blame] | 24 | ProgramStore::ProgramStore(Context *rsc, |
| 25 | bool colorMaskR, bool colorMaskG, bool colorMaskB, bool colorMaskA, |
| 26 | bool depthMask, bool ditherEnable, |
| 27 | RsBlendSrcFunc srcFunc, RsBlendDstFunc destFunc, |
Alex Sakhartchouk | 4385054 | 2011-05-05 16:56:27 -0700 | [diff] [blame] | 28 | RsDepthFunc depthFunc) : ProgramBase(rsc) { |
Jason Sams | 48f5056 | 2011-03-18 15:03:25 -0700 | [diff] [blame] | 29 | memset(&mHal, 0, sizeof(mHal)); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 30 | |
Jason Sams | 331bf9b | 2011-04-06 11:23:54 -0700 | [diff] [blame] | 31 | mHal.state.ditherEnable = ditherEnable; |
Jason Sams | 48f5056 | 2011-03-18 15:03:25 -0700 | [diff] [blame] | 32 | |
Jason Sams | 331bf9b | 2011-04-06 11:23:54 -0700 | [diff] [blame] | 33 | mHal.state.colorRWriteEnable = colorMaskR; |
| 34 | mHal.state.colorGWriteEnable = colorMaskG; |
| 35 | mHal.state.colorBWriteEnable = colorMaskB; |
| 36 | mHal.state.colorAWriteEnable = colorMaskA; |
| 37 | mHal.state.blendSrc = srcFunc; |
| 38 | mHal.state.blendDst = destFunc; |
Jason Sams | 48f5056 | 2011-03-18 15:03:25 -0700 | [diff] [blame] | 39 | |
Jason Sams | 331bf9b | 2011-04-06 11:23:54 -0700 | [diff] [blame] | 40 | mHal.state.depthWriteEnable = depthMask; |
| 41 | mHal.state.depthFunc = depthFunc; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 42 | } |
| 43 | |
Alex Sakhartchouk | 117abdb | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 44 | void ProgramStore::preDestroy() const { |
| 45 | for (uint32_t ct = 0; ct < mRSC->mStateFragmentStore.mStorePrograms.size(); ct++) { |
| 46 | if (mRSC->mStateFragmentStore.mStorePrograms[ct] == this) { |
| 47 | mRSC->mStateFragmentStore.mStorePrograms.removeAt(ct); |
| 48 | break; |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 53 | ProgramStore::~ProgramStore() { |
Jason Sams | 48f5056 | 2011-03-18 15:03:25 -0700 | [diff] [blame] | 54 | mRSC->mHal.funcs.store.destroy(mRSC, this); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Jason Sams | 331bf9b | 2011-04-06 11:23:54 -0700 | [diff] [blame] | 57 | void ProgramStore::setup(const Context *rsc, ProgramStoreState *state) { |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 58 | if (state->mLast.get() == this) { |
| 59 | return; |
| 60 | } |
| 61 | state->mLast.set(this); |
| 62 | |
Jason Sams | 48f5056 | 2011-03-18 15:03:25 -0700 | [diff] [blame] | 63 | rsc->mHal.funcs.store.setActive(rsc, this); |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 64 | } |
| 65 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 66 | void ProgramStore::serialize(OStream *stream) const { |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 67 | } |
| 68 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 69 | ProgramStore *ProgramStore::createFromStream(Context *rsc, IStream *stream) { |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 70 | return NULL; |
| 71 | } |
| 72 | |
Jason Sams | 48f5056 | 2011-03-18 15:03:25 -0700 | [diff] [blame] | 73 | void ProgramStore::init() { |
| 74 | mRSC->mHal.funcs.store.init(mRSC, this); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 77 | ProgramStoreState::ProgramStoreState() { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 80 | ProgramStoreState::~ProgramStoreState() { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Alex Sakhartchouk | 117abdb | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 83 | ObjectBaseRef<ProgramStore> ProgramStore::getProgramStore(Context *rsc, |
| 84 | bool colorMaskR, |
| 85 | bool colorMaskG, |
| 86 | bool colorMaskB, |
| 87 | bool colorMaskA, |
| 88 | bool depthMask, bool ditherEnable, |
| 89 | RsBlendSrcFunc srcFunc, |
| 90 | RsBlendDstFunc destFunc, |
| 91 | RsDepthFunc depthFunc) { |
| 92 | ObjectBaseRef<ProgramStore> returnRef; |
| 93 | ObjectBase::asyncLock(); |
| 94 | for (uint32_t ct = 0; ct < rsc->mStateFragmentStore.mStorePrograms.size(); ct++) { |
| 95 | ProgramStore *existing = rsc->mStateFragmentStore.mStorePrograms[ct]; |
| 96 | if (existing->mHal.state.ditherEnable != ditherEnable) continue; |
| 97 | if (existing->mHal.state.colorRWriteEnable != colorMaskR) continue; |
| 98 | if (existing->mHal.state.colorGWriteEnable != colorMaskG) continue; |
| 99 | if (existing->mHal.state.colorBWriteEnable != colorMaskB) continue; |
| 100 | if (existing->mHal.state.colorAWriteEnable != colorMaskA) continue; |
| 101 | if (existing->mHal.state.blendSrc != srcFunc) continue; |
| 102 | if (existing->mHal.state.blendDst != destFunc) continue; |
| 103 | if (existing->mHal.state.depthWriteEnable != depthMask) continue; |
| 104 | if (existing->mHal.state.depthFunc != depthFunc) continue; |
| 105 | |
| 106 | returnRef.set(existing); |
| 107 | ObjectBase::asyncUnlock(); |
| 108 | return returnRef; |
| 109 | } |
| 110 | ObjectBase::asyncUnlock(); |
| 111 | |
| 112 | ProgramStore *pfs = new ProgramStore(rsc, |
| 113 | colorMaskR, colorMaskG, colorMaskB, colorMaskA, |
| 114 | depthMask, ditherEnable, |
| 115 | srcFunc, destFunc, depthFunc); |
| 116 | returnRef.set(pfs); |
| 117 | |
| 118 | pfs->init(); |
| 119 | |
| 120 | ObjectBase::asyncLock(); |
| 121 | rsc->mStateFragmentStore.mStorePrograms.push(pfs); |
| 122 | ObjectBase::asyncUnlock(); |
| 123 | |
| 124 | return returnRef; |
| 125 | } |
| 126 | |
| 127 | |
| 128 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 129 | void ProgramStoreState::init(Context *rsc) { |
Alex Sakhartchouk | 117abdb | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 130 | mDefault.set(ProgramStore::getProgramStore(rsc, |
| 131 | true, true, true, true, |
| 132 | true, true, |
| 133 | RS_BLEND_SRC_ONE, RS_BLEND_DST_ZERO, |
| 134 | RS_DEPTH_FUNC_LESS).get()); |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 137 | void ProgramStoreState::deinit(Context *rsc) { |
Jason Sams | 61f08d6 | 2009-09-25 16:37:33 -0700 | [diff] [blame] | 138 | mDefault.clear(); |
| 139 | mLast.clear(); |
| 140 | } |
| 141 | |
Jason Sams | 48f5056 | 2011-03-18 15:03:25 -0700 | [diff] [blame] | 142 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 143 | namespace android { |
| 144 | namespace renderscript { |
| 145 | |
Jason Sams | 331bf9b | 2011-04-06 11:23:54 -0700 | [diff] [blame] | 146 | RsProgramStore rsi_ProgramStoreCreate(Context *rsc, |
| 147 | bool colorMaskR, bool colorMaskG, bool colorMaskB, bool colorMaskA, |
| 148 | bool depthMask, bool ditherEnable, |
| 149 | RsBlendSrcFunc srcFunc, RsBlendDstFunc destFunc, |
| 150 | RsDepthFunc depthFunc) { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 151 | |
Alex Sakhartchouk | 117abdb | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 152 | |
| 153 | ObjectBaseRef<ProgramStore> ps = ProgramStore::getProgramStore(rsc, |
| 154 | colorMaskR, colorMaskG, |
| 155 | colorMaskB, colorMaskA, |
| 156 | depthMask, ditherEnable, |
| 157 | srcFunc, destFunc, depthFunc); |
| 158 | ps->incUserRef(); |
| 159 | return ps.get(); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 162 | } |
| 163 | } |