• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "rsProgramRaster.h"
19 
20 namespace android {
21 namespace renderscript {
22 
ProgramRaster(Context * rsc,bool pointSprite,RsCullMode cull)23 ProgramRaster::ProgramRaster(Context *rsc, bool pointSprite, RsCullMode cull)
24     : ProgramBase(rsc) {
25 
26     memset(&mHal, 0, sizeof(mHal));
27     mHal.state.pointSprite = pointSprite;
28     mHal.state.cull = cull;
29     rsc->mHal.funcs.raster.init(rsc, this);
30 }
31 
preDestroy() const32 void ProgramRaster::preDestroy() const {
33     auto& rasterPrograms = mRSC->mStateRaster.mRasterPrograms;
34     for (uint32_t ct = 0; ct < rasterPrograms.size(); ct++) {
35         if (rasterPrograms[ct] == this) {
36             rasterPrograms.erase(rasterPrograms.begin() + ct);
37             break;
38         }
39     }
40 }
41 
~ProgramRaster()42 ProgramRaster::~ProgramRaster() {
43     mRSC->mHal.funcs.raster.destroy(mRSC, this);
44 }
45 
setup(const Context * rsc,ProgramRasterState * state)46 void ProgramRaster::setup(const Context *rsc, ProgramRasterState *state) {
47     if (state->mLast.get() == this && !mDirty) {
48         return;
49     }
50     state->mLast.set(this);
51     mDirty = false;
52 
53     rsc->mHal.funcs.raster.setActive(rsc, this);
54 }
55 
serialize(Context * rsc,OStream * stream) const56 void ProgramRaster::serialize(Context *rsc, OStream *stream) const {
57 }
58 
createFromStream(Context * rsc,IStream * stream)59 ProgramRaster *ProgramRaster::createFromStream(Context *rsc, IStream *stream) {
60     return nullptr;
61 }
62 
ProgramRasterState()63 ProgramRasterState::ProgramRasterState() {
64 }
65 
~ProgramRasterState()66 ProgramRasterState::~ProgramRasterState() {
67 }
68 
init(Context * rsc)69 void ProgramRasterState::init(Context *rsc) {
70     mDefault.set(ProgramRaster::getProgramRaster(rsc, false, RS_CULL_BACK).get());
71 }
72 
deinit(Context * rsc)73 void ProgramRasterState::deinit(Context *rsc) {
74     mDefault.clear();
75     mLast.clear();
76 }
77 
getProgramRaster(Context * rsc,bool pointSprite,RsCullMode cull)78 ObjectBaseRef<ProgramRaster> ProgramRaster::getProgramRaster(Context *rsc,
79                                                              bool pointSprite,
80                                                              RsCullMode cull) {
81     ObjectBaseRef<ProgramRaster> returnRef;
82     ObjectBase::asyncLock();
83     for (uint32_t ct = 0; ct < rsc->mStateRaster.mRasterPrograms.size(); ct++) {
84         ProgramRaster *existing = rsc->mStateRaster.mRasterPrograms[ct];
85         if (existing->mHal.state.pointSprite != pointSprite) continue;
86         if (existing->mHal.state.cull != cull) continue;
87         returnRef.set(existing);
88         ObjectBase::asyncUnlock();
89         return returnRef;
90     }
91     ObjectBase::asyncUnlock();
92 
93     ProgramRaster *pr = new ProgramRaster(rsc, pointSprite, cull);
94     returnRef.set(pr);
95 
96     ObjectBase::asyncLock();
97     rsc->mStateRaster.mRasterPrograms.push_back(pr);
98     ObjectBase::asyncUnlock();
99 
100     return returnRef;
101 }
102 
rsi_ProgramRasterCreate(Context * rsc,bool pointSprite,RsCullMode cull)103 RsProgramRaster rsi_ProgramRasterCreate(Context * rsc, bool pointSprite, RsCullMode cull) {
104     ObjectBaseRef<ProgramRaster> pr = ProgramRaster::getProgramRaster(rsc, pointSprite, cull);
105     pr->incUserRef();
106     return pr.get();
107 }
108 
109 } // namespace renderscript
110 } // namespace android
111