blob: 772c182ec0a5e4d48dbe59159ff3fe6bc83d22a6 [file] [log] [blame]
Jason Sams5fd09d82009-09-23 13:57:02 -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 Sakhartchoukfb6b6142010-05-21 12:53:13 -070018#include "rsProgramRaster.h"
Jason Sams5fd09d82009-09-23 13:57:02 -070019
Chih-Hung Hsieh11496ac2016-11-15 15:14:05 -080020namespace android {
21namespace renderscript {
Jason Sams5fd09d82009-09-23 13:57:02 -070022
Jason Sams5b9f3e22011-09-23 14:18:53 -070023ProgramRaster::ProgramRaster(Context *rsc, bool pointSprite, RsCullMode cull)
Alex Sakhartchouk7f126c72011-05-05 16:56:27 -070024 : ProgramBase(rsc) {
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080025
Jason Sams721acc42011-04-06 11:23:54 -070026 memset(&mHal, 0, sizeof(mHal));
Jason Sams721acc42011-04-06 11:23:54 -070027 mHal.state.pointSprite = pointSprite;
Jason Sams721acc42011-04-06 11:23:54 -070028 mHal.state.cull = cull;
Jason Sams721acc42011-04-06 11:23:54 -070029 rsc->mHal.funcs.raster.init(rsc, this);
Jason Sams5fd09d82009-09-23 13:57:02 -070030}
31
Alex Sakhartchoukc700e642011-08-16 13:09:46 -070032void ProgramRaster::preDestroy() const {
Yang Nib8353c52015-02-14 18:00:59 -080033 for (uint32_t ct = 0; ct < mRSC->mStateRaster.mRasterPrograms.size(); ct++) {
34 if (mRSC->mStateRaster.mRasterPrograms[ct] == this) {
35 mRSC->mStateRaster.mRasterPrograms.removeAt(ct);
36 break;
Alex Sakhartchoukc700e642011-08-16 13:09:46 -070037 }
38 }
39}
40
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080041ProgramRaster::~ProgramRaster() {
Jason Sams721acc42011-04-06 11:23:54 -070042 mRSC->mHal.funcs.raster.destroy(mRSC, this);
Jason Sams5fd09d82009-09-23 13:57:02 -070043}
44
Jason Sams721acc42011-04-06 11:23:54 -070045void ProgramRaster::setup(const Context *rsc, ProgramRasterState *state) {
Alex Sakhartchoukd18c7442010-07-12 15:50:32 -070046 if (state->mLast.get() == this && !mDirty) {
Jason Samsc460e552009-11-25 13:22:07 -080047 return;
48 }
49 state->mLast.set(this);
Alex Sakhartchoukd18c7442010-07-12 15:50:32 -070050 mDirty = false;
51
Jason Sams721acc42011-04-06 11:23:54 -070052 rsc->mHal.funcs.raster.setActive(rsc, this);
Jason Samsc460e552009-11-25 13:22:07 -080053}
54
Jason Samse3150cf2012-07-24 18:10:20 -070055void ProgramRaster::serialize(Context *rsc, OStream *stream) const {
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070056}
Jason Sams5fd09d82009-09-23 13:57:02 -070057
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080058ProgramRaster *ProgramRaster::createFromStream(Context *rsc, IStream *stream) {
Chris Wailes44bef6f2014-08-12 13:51:10 -070059 return nullptr;
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070060}
Jason Sams5fd09d82009-09-23 13:57:02 -070061
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080062ProgramRasterState::ProgramRasterState() {
Jason Sams5fd09d82009-09-23 13:57:02 -070063}
64
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080065ProgramRasterState::~ProgramRasterState() {
Jason Sams5fd09d82009-09-23 13:57:02 -070066}
67
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080068void ProgramRasterState::init(Context *rsc) {
Jason Sams5b9f3e22011-09-23 14:18:53 -070069 mDefault.set(ProgramRaster::getProgramRaster(rsc, false, RS_CULL_BACK).get());
Jason Sams5fd09d82009-09-23 13:57:02 -070070}
71
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080072void ProgramRasterState::deinit(Context *rsc) {
Jason Samsf2649a92009-09-25 16:37:33 -070073 mDefault.clear();
74 mLast.clear();
75}
76
Alex Sakhartchoukc700e642011-08-16 13:09:46 -070077ObjectBaseRef<ProgramRaster> ProgramRaster::getProgramRaster(Context *rsc,
Alex Sakhartchoukc700e642011-08-16 13:09:46 -070078 bool pointSprite,
Alex Sakhartchoukc700e642011-08-16 13:09:46 -070079 RsCullMode cull) {
80 ObjectBaseRef<ProgramRaster> returnRef;
81 ObjectBase::asyncLock();
82 for (uint32_t ct = 0; ct < rsc->mStateRaster.mRasterPrograms.size(); ct++) {
83 ProgramRaster *existing = rsc->mStateRaster.mRasterPrograms[ct];
Alex Sakhartchoukc700e642011-08-16 13:09:46 -070084 if (existing->mHal.state.pointSprite != pointSprite) continue;
Alex Sakhartchoukc700e642011-08-16 13:09:46 -070085 if (existing->mHal.state.cull != cull) continue;
86 returnRef.set(existing);
87 ObjectBase::asyncUnlock();
88 return returnRef;
89 }
90 ObjectBase::asyncUnlock();
91
Jason Sams5b9f3e22011-09-23 14:18:53 -070092 ProgramRaster *pr = new ProgramRaster(rsc, pointSprite, cull);
Alex Sakhartchoukc700e642011-08-16 13:09:46 -070093 returnRef.set(pr);
94
95 ObjectBase::asyncLock();
Yang Nib8353c52015-02-14 18:00:59 -080096 rsc->mStateRaster.mRasterPrograms.push(pr);
Alex Sakhartchoukc700e642011-08-16 13:09:46 -070097 ObjectBase::asyncUnlock();
98
99 return returnRef;
100}
101
Jason Sams5b9f3e22011-09-23 14:18:53 -0700102RsProgramRaster rsi_ProgramRasterCreate(Context * rsc, bool pointSprite, RsCullMode cull) {
103 ObjectBaseRef<ProgramRaster> pr = ProgramRaster::getProgramRaster(rsc, pointSprite, cull);
Jason Sams5fd09d82009-09-23 13:57:02 -0700104 pr->incUserRef();
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700105 return pr.get();
Jason Sams5fd09d82009-09-23 13:57:02 -0700106}
107
Chih-Hung Hsieh11496ac2016-11-15 15:14:05 -0800108} // namespace renderscript
109} // namespace android