rsProgramStore.cpp revision 7f126c78a107257090c6675ea40ffac41516a9dc
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
24721acc495b859c6d884725a4f9b5523583dd11c7Jason SamsProgramStore::ProgramStore(Context *rsc,
25721acc495b859c6d884725a4f9b5523583dd11c7Jason Sams                           bool colorMaskR, bool colorMaskG, bool colorMaskB, bool colorMaskA,
26721acc495b859c6d884725a4f9b5523583dd11c7Jason Sams                           bool depthMask, bool ditherEnable,
27721acc495b859c6d884725a4f9b5523583dd11c7Jason Sams                           RsBlendSrcFunc srcFunc, RsBlendDstFunc destFunc,
287f126c78a107257090c6675ea40ffac41516a9dcAlex Sakhartchouk                           RsDepthFunc depthFunc) : ProgramBase(rsc) {
298feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams    memset(&mHal, 0, sizeof(mHal));
308feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams
31721acc495b859c6d884725a4f9b5523583dd11c7Jason Sams    mHal.state.ditherEnable = ditherEnable;
328feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams
33721acc495b859c6d884725a4f9b5523583dd11c7Jason Sams    mHal.state.colorRWriteEnable = colorMaskR;
34721acc495b859c6d884725a4f9b5523583dd11c7Jason Sams    mHal.state.colorGWriteEnable = colorMaskG;
35721acc495b859c6d884725a4f9b5523583dd11c7Jason Sams    mHal.state.colorBWriteEnable = colorMaskB;
36721acc495b859c6d884725a4f9b5523583dd11c7Jason Sams    mHal.state.colorAWriteEnable = colorMaskA;
37721acc495b859c6d884725a4f9b5523583dd11c7Jason Sams    mHal.state.blendSrc = srcFunc;
38721acc495b859c6d884725a4f9b5523583dd11c7Jason Sams    mHal.state.blendDst = destFunc;
398feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams
40721acc495b859c6d884725a4f9b5523583dd11c7Jason Sams    mHal.state.depthWriteEnable = depthMask;
41721acc495b859c6d884725a4f9b5523583dd11c7Jason Sams    mHal.state.depthFunc = depthFunc;
42326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
43326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
44afb743aca56c18beb7ab924e75cb6e070ef3e55aAlex SakhartchoukProgramStore::~ProgramStore() {
458feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams    mRSC->mHal.funcs.store.destroy(mRSC, this);
46326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
47326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
48721acc495b859c6d884725a4f9b5523583dd11c7Jason Samsvoid ProgramStore::setup(const Context *rsc, ProgramStoreState *state) {
49c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams    if (state->mLast.get() == this) {
50c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams        return;
51c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams    }
52c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams    state->mLast.set(this);
53c460e55d78cbe8bee95c5c947dfe541218142a5bJason Sams
548feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams    rsc->mHal.funcs.store.setActive(rsc, this);
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
648feea4e0dec48ea03bd6d32706d058b86dddc5baJason Samsvoid ProgramStore::init() {
658feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams    mRSC->mHal.funcs.store.init(mRSC, this);
66326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
67326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
68afb743aca56c18beb7ab924e75cb6e070ef3e55aAlex SakhartchoukProgramStoreState::ProgramStoreState() {
69326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
70326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
71afb743aca56c18beb7ab924e75cb6e070ef3e55aAlex SakhartchoukProgramStoreState::~ProgramStoreState() {
72326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
73326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
74afb743aca56c18beb7ab924e75cb6e070ef3e55aAlex Sakhartchoukvoid ProgramStoreState::init(Context *rsc) {
75721acc495b859c6d884725a4f9b5523583dd11c7Jason Sams    ProgramStore *ps = new ProgramStore(rsc,
76721acc495b859c6d884725a4f9b5523583dd11c7Jason Sams                                        true, true, true, true,
77721acc495b859c6d884725a4f9b5523583dd11c7Jason Sams                                        true, true,
78721acc495b859c6d884725a4f9b5523583dd11c7Jason Sams                                        RS_BLEND_SRC_ONE, RS_BLEND_DST_ZERO,
79721acc495b859c6d884725a4f9b5523583dd11c7Jason Sams                                        RS_DEPTH_FUNC_LESS);
80721acc495b859c6d884725a4f9b5523583dd11c7Jason Sams    ps->init();
81721acc495b859c6d884725a4f9b5523583dd11c7Jason Sams    mDefault.set(ps);
828ce125be69531dbf3a7e856d5e59d1b8e2789db0Jason Sams}
838ce125be69531dbf3a7e856d5e59d1b8e2789db0Jason Sams
84afb743aca56c18beb7ab924e75cb6e070ef3e55aAlex Sakhartchoukvoid ProgramStoreState::deinit(Context *rsc) {
85f2649a961db2995e9e24a6c98f8a419f1496c1b7Jason Sams    mDefault.clear();
86f2649a961db2995e9e24a6c98f8a419f1496c1b7Jason Sams    mLast.clear();
87f2649a961db2995e9e24a6c98f8a419f1496c1b7Jason Sams}
88f2649a961db2995e9e24a6c98f8a419f1496c1b7Jason Sams
898feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams
90326e0ddf89e8df2837752fbfd7a014814b32082cJason Samsnamespace android {
91326e0ddf89e8df2837752fbfd7a014814b32082cJason Samsnamespace renderscript {
92326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
93721acc495b859c6d884725a4f9b5523583dd11c7Jason SamsRsProgramStore rsi_ProgramStoreCreate(Context *rsc,
94721acc495b859c6d884725a4f9b5523583dd11c7Jason Sams                                      bool colorMaskR, bool colorMaskG, bool colorMaskB, bool colorMaskA,
95721acc495b859c6d884725a4f9b5523583dd11c7Jason Sams                                      bool depthMask, bool ditherEnable,
96721acc495b859c6d884725a4f9b5523583dd11c7Jason Sams                                      RsBlendSrcFunc srcFunc, RsBlendDstFunc destFunc,
97721acc495b859c6d884725a4f9b5523583dd11c7Jason Sams                                      RsDepthFunc depthFunc) {
98326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
99721acc495b859c6d884725a4f9b5523583dd11c7Jason Sams    ProgramStore *pfs = new ProgramStore(rsc,
100721acc495b859c6d884725a4f9b5523583dd11c7Jason Sams                                         colorMaskR, colorMaskG, colorMaskB, colorMaskA,
101721acc495b859c6d884725a4f9b5523583dd11c7Jason Sams                                         depthMask, ditherEnable,
102721acc495b859c6d884725a4f9b5523583dd11c7Jason Sams                                         srcFunc, destFunc, depthFunc);
1038feea4e0dec48ea03bd6d32706d058b86dddc5baJason Sams    pfs->init();
1049397e30ce5fe3f6af9212a93b490836b04fdfffaJason Sams    pfs->incUserRef();
105326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    return pfs;
106326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
107326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
108326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
109326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
110