Jason Sams | 5fd09d8 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 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" |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 18 | #include "rsProgramRaster.h" |
Jason Sams | 5fd09d8 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 19 | |
Chih-Hung Hsieh | 11496ac | 2016-11-15 15:14:05 -0800 | [diff] [blame] | 20 | namespace android { |
| 21 | namespace renderscript { |
Jason Sams | 5fd09d8 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 22 | |
Jason Sams | 5b9f3e2 | 2011-09-23 14:18:53 -0700 | [diff] [blame] | 23 | ProgramRaster::ProgramRaster(Context *rsc, bool pointSprite, RsCullMode cull) |
Alex Sakhartchouk | 7f126c7 | 2011-05-05 16:56:27 -0700 | [diff] [blame] | 24 | : ProgramBase(rsc) { |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 25 | |
Jason Sams | 721acc4 | 2011-04-06 11:23:54 -0700 | [diff] [blame] | 26 | memset(&mHal, 0, sizeof(mHal)); |
Jason Sams | 721acc4 | 2011-04-06 11:23:54 -0700 | [diff] [blame] | 27 | mHal.state.pointSprite = pointSprite; |
Jason Sams | 721acc4 | 2011-04-06 11:23:54 -0700 | [diff] [blame] | 28 | mHal.state.cull = cull; |
Jason Sams | 721acc4 | 2011-04-06 11:23:54 -0700 | [diff] [blame] | 29 | rsc->mHal.funcs.raster.init(rsc, this); |
Jason Sams | 5fd09d8 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 30 | } |
| 31 | |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 32 | void ProgramRaster::preDestroy() const { |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 33 | 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 Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 37 | } |
| 38 | } |
| 39 | } |
| 40 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 41 | ProgramRaster::~ProgramRaster() { |
Jason Sams | 721acc4 | 2011-04-06 11:23:54 -0700 | [diff] [blame] | 42 | mRSC->mHal.funcs.raster.destroy(mRSC, this); |
Jason Sams | 5fd09d8 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 43 | } |
| 44 | |
Jason Sams | 721acc4 | 2011-04-06 11:23:54 -0700 | [diff] [blame] | 45 | void ProgramRaster::setup(const Context *rsc, ProgramRasterState *state) { |
Alex Sakhartchouk | d18c744 | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 46 | if (state->mLast.get() == this && !mDirty) { |
Jason Sams | c460e55 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 47 | return; |
| 48 | } |
| 49 | state->mLast.set(this); |
Alex Sakhartchouk | d18c744 | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 50 | mDirty = false; |
| 51 | |
Jason Sams | 721acc4 | 2011-04-06 11:23:54 -0700 | [diff] [blame] | 52 | rsc->mHal.funcs.raster.setActive(rsc, this); |
Jason Sams | c460e55 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 53 | } |
| 54 | |
Jason Sams | e3150cf | 2012-07-24 18:10:20 -0700 | [diff] [blame] | 55 | void ProgramRaster::serialize(Context *rsc, OStream *stream) const { |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 56 | } |
Jason Sams | 5fd09d8 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 57 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 58 | ProgramRaster *ProgramRaster::createFromStream(Context *rsc, IStream *stream) { |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 59 | return nullptr; |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 60 | } |
Jason Sams | 5fd09d8 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 61 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 62 | ProgramRasterState::ProgramRasterState() { |
Jason Sams | 5fd09d8 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 65 | ProgramRasterState::~ProgramRasterState() { |
Jason Sams | 5fd09d8 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 68 | void ProgramRasterState::init(Context *rsc) { |
Jason Sams | 5b9f3e2 | 2011-09-23 14:18:53 -0700 | [diff] [blame] | 69 | mDefault.set(ProgramRaster::getProgramRaster(rsc, false, RS_CULL_BACK).get()); |
Jason Sams | 5fd09d8 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 72 | void ProgramRasterState::deinit(Context *rsc) { |
Jason Sams | f2649a9 | 2009-09-25 16:37:33 -0700 | [diff] [blame] | 73 | mDefault.clear(); |
| 74 | mLast.clear(); |
| 75 | } |
| 76 | |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 77 | ObjectBaseRef<ProgramRaster> ProgramRaster::getProgramRaster(Context *rsc, |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 78 | bool pointSprite, |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 79 | 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 Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 84 | if (existing->mHal.state.pointSprite != pointSprite) continue; |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 85 | if (existing->mHal.state.cull != cull) continue; |
| 86 | returnRef.set(existing); |
| 87 | ObjectBase::asyncUnlock(); |
| 88 | return returnRef; |
| 89 | } |
| 90 | ObjectBase::asyncUnlock(); |
| 91 | |
Jason Sams | 5b9f3e2 | 2011-09-23 14:18:53 -0700 | [diff] [blame] | 92 | ProgramRaster *pr = new ProgramRaster(rsc, pointSprite, cull); |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 93 | returnRef.set(pr); |
| 94 | |
| 95 | ObjectBase::asyncLock(); |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 96 | rsc->mStateRaster.mRasterPrograms.push(pr); |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 97 | ObjectBase::asyncUnlock(); |
| 98 | |
| 99 | return returnRef; |
| 100 | } |
| 101 | |
Jason Sams | 5b9f3e2 | 2011-09-23 14:18:53 -0700 | [diff] [blame] | 102 | RsProgramRaster rsi_ProgramRasterCreate(Context * rsc, bool pointSprite, RsCullMode cull) { |
| 103 | ObjectBaseRef<ProgramRaster> pr = ProgramRaster::getProgramRaster(rsc, pointSprite, cull); |
Jason Sams | 5fd09d8 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 104 | pr->incUserRef(); |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 105 | return pr.get(); |
Jason Sams | 5fd09d8 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Chih-Hung Hsieh | 11496ac | 2016-11-15 15:14:05 -0800 | [diff] [blame] | 108 | } // namespace renderscript |
| 109 | } // namespace android |