rsProgramStore.cpp revision 7f126c78a107257090c6675ea40ffac41516a9dc
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"
18#include "rsProgramStore.h"
19
20using namespace android;
21using namespace android::renderscript;
22
23
24ProgramStore::ProgramStore(Context *rsc,
25                           bool colorMaskR, bool colorMaskG, bool colorMaskB, bool colorMaskA,
26                           bool depthMask, bool ditherEnable,
27                           RsBlendSrcFunc srcFunc, RsBlendDstFunc destFunc,
28                           RsDepthFunc depthFunc) : ProgramBase(rsc) {
29    memset(&mHal, 0, sizeof(mHal));
30
31    mHal.state.ditherEnable = ditherEnable;
32
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;
39
40    mHal.state.depthWriteEnable = depthMask;
41    mHal.state.depthFunc = depthFunc;
42}
43
44ProgramStore::~ProgramStore() {
45    mRSC->mHal.funcs.store.destroy(mRSC, this);
46}
47
48void ProgramStore::setup(const Context *rsc, ProgramStoreState *state) {
49    if (state->mLast.get() == this) {
50        return;
51    }
52    state->mLast.set(this);
53
54    rsc->mHal.funcs.store.setActive(rsc, this);
55}
56
57void ProgramStore::serialize(OStream *stream) const {
58}
59
60ProgramStore *ProgramStore::createFromStream(Context *rsc, IStream *stream) {
61    return NULL;
62}
63
64void ProgramStore::init() {
65    mRSC->mHal.funcs.store.init(mRSC, this);
66}
67
68ProgramStoreState::ProgramStoreState() {
69}
70
71ProgramStoreState::~ProgramStoreState() {
72}
73
74void ProgramStoreState::init(Context *rsc) {
75    ProgramStore *ps = new ProgramStore(rsc,
76                                        true, true, true, true,
77                                        true, true,
78                                        RS_BLEND_SRC_ONE, RS_BLEND_DST_ZERO,
79                                        RS_DEPTH_FUNC_LESS);
80    ps->init();
81    mDefault.set(ps);
82}
83
84void ProgramStoreState::deinit(Context *rsc) {
85    mDefault.clear();
86    mLast.clear();
87}
88
89
90namespace android {
91namespace renderscript {
92
93RsProgramStore rsi_ProgramStoreCreate(Context *rsc,
94                                      bool colorMaskR, bool colorMaskG, bool colorMaskB, bool colorMaskA,
95                                      bool depthMask, bool ditherEnable,
96                                      RsBlendSrcFunc srcFunc, RsBlendDstFunc destFunc,
97                                      RsDepthFunc depthFunc) {
98
99    ProgramStore *pfs = new ProgramStore(rsc,
100                                         colorMaskR, colorMaskG, colorMaskB, colorMaskA,
101                                         depthMask, ditherEnable,
102                                         srcFunc, destFunc, depthFunc);
103    pfs->init();
104    pfs->incUserRef();
105    return pfs;
106}
107
108}
109}
110