blob: 7e25a226d8ae9b47f6033248b3cc0af73eea0fff [file] [log] [blame]
Jason Samsd19f10d2009-05-22 14:03:28 -07001/*
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 Sakhartchoukaa7d2882010-05-21 12:53:13 -070018#include "rsProgramStore.h"
Jason Sams4b962e52009-06-22 17:15:15 -070019
Jason Samsd19f10d2009-05-22 14:03:28 -070020using namespace android;
21using namespace android::renderscript;
22
23
Jason Sams331bf9b2011-04-06 11:23:54 -070024ProgramStore::ProgramStore(Context *rsc,
25 bool colorMaskR, bool colorMaskG, bool colorMaskB, bool colorMaskA,
26 bool depthMask, bool ditherEnable,
27 RsBlendSrcFunc srcFunc, RsBlendDstFunc destFunc,
Alex Sakhartchouk43850542011-05-05 16:56:27 -070028 RsDepthFunc depthFunc) : ProgramBase(rsc) {
Jason Sams48f50562011-03-18 15:03:25 -070029 memset(&mHal, 0, sizeof(mHal));
Jason Samsd19f10d2009-05-22 14:03:28 -070030
Jason Sams331bf9b2011-04-06 11:23:54 -070031 mHal.state.ditherEnable = ditherEnable;
Jason Sams48f50562011-03-18 15:03:25 -070032
Jason Sams331bf9b2011-04-06 11:23:54 -070033 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 Sams48f50562011-03-18 15:03:25 -070039
Jason Sams331bf9b2011-04-06 11:23:54 -070040 mHal.state.depthWriteEnable = depthMask;
41 mHal.state.depthFunc = depthFunc;
Jason Samsd19f10d2009-05-22 14:03:28 -070042}
43
Alex Sakhartchouk117abdb2011-08-16 13:09:46 -070044void 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 Sakhartchouked9f2102010-11-09 17:00:54 -080053ProgramStore::~ProgramStore() {
Jason Sams48f50562011-03-18 15:03:25 -070054 mRSC->mHal.funcs.store.destroy(mRSC, this);
Jason Samsd19f10d2009-05-22 14:03:28 -070055}
56
Jason Sams331bf9b2011-04-06 11:23:54 -070057void ProgramStore::setup(const Context *rsc, ProgramStoreState *state) {
Jason Samsbb51c402009-11-25 13:22:07 -080058 if (state->mLast.get() == this) {
59 return;
60 }
61 state->mLast.set(this);
62
Jason Sams48f50562011-03-18 15:03:25 -070063 rsc->mHal.funcs.store.setActive(rsc, this);
Jason Samsbb51c402009-11-25 13:22:07 -080064}
65
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080066void ProgramStore::serialize(OStream *stream) const {
Alex Sakhartchoukaa7d2882010-05-21 12:53:13 -070067}
68
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080069ProgramStore *ProgramStore::createFromStream(Context *rsc, IStream *stream) {
Alex Sakhartchoukaa7d2882010-05-21 12:53:13 -070070 return NULL;
71}
72
Jason Sams48f50562011-03-18 15:03:25 -070073void ProgramStore::init() {
74 mRSC->mHal.funcs.store.init(mRSC, this);
Jason Samsd19f10d2009-05-22 14:03:28 -070075}
76
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080077ProgramStoreState::ProgramStoreState() {
Jason Samsd19f10d2009-05-22 14:03:28 -070078}
79
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080080ProgramStoreState::~ProgramStoreState() {
Jason Samsd19f10d2009-05-22 14:03:28 -070081}
82
Alex Sakhartchouk117abdb2011-08-16 13:09:46 -070083ObjectBaseRef<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 Sakhartchouked9f2102010-11-09 17:00:54 -0800129void ProgramStoreState::init(Context *rsc) {
Alex Sakhartchouk117abdb2011-08-16 13:09:46 -0700130 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 Sams9c54bdb2009-06-17 16:52:59 -0700135}
136
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800137void ProgramStoreState::deinit(Context *rsc) {
Jason Sams61f08d62009-09-25 16:37:33 -0700138 mDefault.clear();
139 mLast.clear();
140}
141
Jason Sams48f50562011-03-18 15:03:25 -0700142
Jason Samsd19f10d2009-05-22 14:03:28 -0700143namespace android {
144namespace renderscript {
145
Jason Sams331bf9b2011-04-06 11:23:54 -0700146RsProgramStore 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 Samsd19f10d2009-05-22 14:03:28 -0700151
Alex Sakhartchouk117abdb2011-08-16 13:09:46 -0700152
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 Samsd19f10d2009-05-22 14:03:28 -0700160}
161
Jason Samsd19f10d2009-05-22 14:03:28 -0700162}
163}