rsProgramStore.cpp revision 8feea4e0dec48ea03bd6d32706d058b86dddc5ba
1326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams/*
2326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * Copyright (C) 2009 The Android Open Source Project
3326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams *
4326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * Licensed under the Apache License, Version 2.0 (the "License");
5326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * you may not use this file except in compliance with the License.
6326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * You may obtain a copy of the License at
7326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams *
8326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams *      http://www.apache.org/licenses/LICENSE-2.0
9326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams *
10326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * Unless required by applicable law or agreed to in writing, software
11326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * distributed under the License is distributed on an "AS IS" BASIS,
12326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * See the License for the specific language governing permissions and
14326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * limitations under the License.
15326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams */
16326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
17326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams#include "rsContext.h"
18fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk#include "rsProgramStore.h"
191aa5a4eb81b8b88aeb5d2b6f4c47356fd0a62923Jason Sams
20326e0ddf89e8df2837752fbfd7a014814b32082cJason Samsusing namespace android;
21326e0ddf89e8df2837752fbfd7a014814b32082cJason Samsusing namespace android::renderscript;
22326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
23326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
24afb743aca56c18beb7ab924e75cb6e070ef3e55aAlex SakhartchoukProgramStore::ProgramStore(Context *rsc) : Program(rsc) {
258feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams    memset(&mHal, 0, sizeof(mHal));
268feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams
278feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams    mHal.state.ditherEnable = true;
288feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams
298feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams    mHal.state.colorRWriteEnable = true;
308feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams    mHal.state.colorGWriteEnable = true;
318feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams    mHal.state.colorBWriteEnable = true;
328feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams    mHal.state.colorAWriteEnable = true;
338feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams    mHal.state.blendSrc = RS_BLEND_SRC_ONE;
348feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams    mHal.state.blendDst = RS_BLEND_DST_ZERO;
358feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams
368feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams    mHal.state.depthWriteEnable = true;
378feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams    mHal.state.depthFunc = RS_DEPTH_FUNC_LESS;
38326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
39326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
40afb743aca56c18beb7ab924e75cb6e070ef3e55aAlex SakhartchoukProgramStore::~ProgramStore() {
418feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams    mRSC->mHal.funcs.store.destroy(mRSC, this);
42326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
43326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
44afb743aca56c18beb7ab924e75cb6e070ef3e55aAlex Sakhartchoukvoid ProgramStore::setupGL2(const Context *rsc, ProgramStoreState *state) {
45c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams    if (state->mLast.get() == this) {
46c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams        return;
47c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams    }
48c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams    state->mLast.set(this);
49c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams
508feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams    rsc->mHal.funcs.store.setActive(rsc, this);
51326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
52326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
53afb743aca56c18beb7ab924e75cb6e070ef3e55aAlex Sakhartchoukvoid ProgramStore::setDitherEnable(bool enable) {
548feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams    mHal.state.ditherEnable = enable;
55326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
56326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
57afb743aca56c18beb7ab924e75cb6e070ef3e55aAlex Sakhartchoukvoid ProgramStore::serialize(OStream *stream) const {
58fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk}
59fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk
60afb743aca56c18beb7ab924e75cb6e070ef3e55aAlex SakhartchoukProgramStore *ProgramStore::createFromStream(Context *rsc, IStream *stream) {
61fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk    return NULL;
62fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk}
63fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk
64afb743aca56c18beb7ab924e75cb6e070ef3e55aAlex Sakhartchoukvoid ProgramStore::setDepthFunc(RsDepthFunc func) {
658feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams    mHal.state.depthFunc = func;
66326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
67326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
68afb743aca56c18beb7ab924e75cb6e070ef3e55aAlex Sakhartchoukvoid ProgramStore::setDepthMask(bool mask) {
698feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams    mHal.state.depthWriteEnable = mask;
70326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
71326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
72afb743aca56c18beb7ab924e75cb6e070ef3e55aAlex Sakhartchoukvoid ProgramStore::setBlendFunc(RsBlendSrcFunc src, RsBlendDstFunc dst) {
738feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams    mHal.state.blendSrc = src;
748feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams    mHal.state.blendDst = dst;
75326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
76326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
77afb743aca56c18beb7ab924e75cb6e070ef3e55aAlex Sakhartchoukvoid ProgramStore::setColorMask(bool r, bool g, bool b, bool a) {
788feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams    mHal.state.colorRWriteEnable = r;
798feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams    mHal.state.colorGWriteEnable = g;
808feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams    mHal.state.colorBWriteEnable = b;
818feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams    mHal.state.colorAWriteEnable = a;
828feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams}
838feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams
848feea4e0dec48ea03bd6d32706d058b86dddc5baJason Samsvoid ProgramStore::init() {
858feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams    mRSC->mHal.funcs.store.init(mRSC, this);
86326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
87326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
88afb743aca56c18beb7ab924e75cb6e070ef3e55aAlex SakhartchoukProgramStoreState::ProgramStoreState() {
89326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    mPFS = NULL;
90326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
91326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
92afb743aca56c18beb7ab924e75cb6e070ef3e55aAlex SakhartchoukProgramStoreState::~ProgramStoreState() {
93225afd317e101a7be5fe02c0a86361146ea89f05Jason Sams    ObjectBase::checkDelete(mPFS);
94225afd317e101a7be5fe02c0a86361146ea89f05Jason Sams    mPFS = NULL;
95326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
96326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
97afb743aca56c18beb7ab924e75cb6e070ef3e55aAlex Sakhartchoukvoid ProgramStoreState::init(Context *rsc) {
98ccc010bb7c0f89e162bf60033968a20be90a903aJason Sams    ProgramStore *pfs = new ProgramStore(rsc);
998feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams    pfs->init();
1008ce125be69531dbf3a7e856d5e59d1b8e2789db0Jason Sams    mDefault.set(pfs);
1018ce125be69531dbf3a7e856d5e59d1b8e2789db0Jason Sams}
1028ce125be69531dbf3a7e856d5e59d1b8e2789db0Jason Sams
103afb743aca56c18beb7ab924e75cb6e070ef3e55aAlex Sakhartchoukvoid ProgramStoreState::deinit(Context *rsc) {
104f2649a961db2995e9e24a6c98f8a419f1496c1b7Jason Sams    mDefault.clear();
105f2649a961db2995e9e24a6c98f8a419f1496c1b7Jason Sams    mLast.clear();
106f2649a961db2995e9e24a6c98f8a419f1496c1b7Jason Sams}
107f2649a961db2995e9e24a6c98f8a419f1496c1b7Jason Sams
1088feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams
109326e0ddf89e8df2837752fbfd7a014814b32082cJason Samsnamespace android {
110326e0ddf89e8df2837752fbfd7a014814b32082cJason Samsnamespace renderscript {
111326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
112afb743aca56c18beb7ab924e75cb6e070ef3e55aAlex Sakhartchoukvoid rsi_ProgramStoreBegin(Context * rsc, RsElement in, RsElement out) {
113225afd317e101a7be5fe02c0a86361146ea89f05Jason Sams    ObjectBase::checkDelete(rsc->mStateFragmentStore.mPFS);
114ccc010bb7c0f89e162bf60033968a20be90a903aJason Sams    rsc->mStateFragmentStore.mPFS = new ProgramStore(rsc);
115326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
116326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
117afb743aca56c18beb7ab924e75cb6e070ef3e55aAlex Sakhartchoukvoid rsi_ProgramStoreDepthFunc(Context *rsc, RsDepthFunc func) {
118326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    rsc->mStateFragmentStore.mPFS->setDepthFunc(func);
119326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
120326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
121afb743aca56c18beb7ab924e75cb6e070ef3e55aAlex Sakhartchoukvoid rsi_ProgramStoreDepthMask(Context *rsc, bool mask) {
122326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    rsc->mStateFragmentStore.mPFS->setDepthMask(mask);
123326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
124326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
125afb743aca56c18beb7ab924e75cb6e070ef3e55aAlex Sakhartchoukvoid rsi_ProgramStoreColorMask(Context *rsc, bool r, bool g, bool b, bool a) {
126326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    rsc->mStateFragmentStore.mPFS->setColorMask(r, g, b, a);
127326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
128326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
129afb743aca56c18beb7ab924e75cb6e070ef3e55aAlex Sakhartchoukvoid rsi_ProgramStoreBlendFunc(Context *rsc, RsBlendSrcFunc src, RsBlendDstFunc dst) {
130326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    rsc->mStateFragmentStore.mPFS->setBlendFunc(src, dst);
131326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
132326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
133afb743aca56c18beb7ab924e75cb6e070ef3e55aAlex SakhartchoukRsProgramStore rsi_ProgramStoreCreate(Context *rsc) {
134ccc010bb7c0f89e162bf60033968a20be90a903aJason Sams    ProgramStore *pfs = rsc->mStateFragmentStore.mPFS;
1358feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams    pfs->init();
1369397e30ce5fe3f6af9212a93b490836b04fdfffaJason Sams    pfs->incUserRef();
137326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    rsc->mStateFragmentStore.mPFS = 0;
138326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    return pfs;
139326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
140326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
141afb743aca56c18beb7ab924e75cb6e070ef3e55aAlex Sakhartchoukvoid rsi_ProgramStoreDither(Context *rsc, bool enable) {
142326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    rsc->mStateFragmentStore.mPFS->setDitherEnable(enable);
143326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
144326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
145326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
146326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
147