Alex Sakhartchouk | 7d9c5ff | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 "rsFBOCache.h" |
| 18 | |
| 19 | #include "rsContext.h" |
| 20 | #include "rsAllocation.h" |
| 21 | |
Alex Sakhartchouk | 7d9c5ff | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 22 | using namespace android; |
| 23 | using namespace android::renderscript; |
| 24 | |
| 25 | |
| 26 | FBOCache::FBOCache() { |
Alex Sakhartchouk | c19ff01 | 2011-05-06 14:59:45 -0700 | [diff] [blame] | 27 | mDirty = true; |
Alex Sakhartchouk | da6d34a | 2011-05-13 14:53:34 -0700 | [diff] [blame] | 28 | mHal.state.colorTargetsCount = 1; |
Alex Sakhartchouk | 064aa7e | 2011-10-18 10:54:29 -0700 | [diff] [blame] | 29 | mHal.state.colorTargets = new Allocation*[mHal.state.colorTargetsCount]; |
| 30 | mColorTargets = new ObjectBaseRef<Allocation>[mHal.state.colorTargetsCount]; |
| 31 | resetAll(NULL); |
Alex Sakhartchouk | 7d9c5ff | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | FBOCache::~FBOCache() { |
Alex Sakhartchouk | da6d34a | 2011-05-13 14:53:34 -0700 | [diff] [blame] | 35 | delete[] mHal.state.colorTargets; |
Alex Sakhartchouk | 064aa7e | 2011-10-18 10:54:29 -0700 | [diff] [blame] | 36 | delete[] mColorTargets; |
Alex Sakhartchouk | da6d34a | 2011-05-13 14:53:34 -0700 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | void FBOCache::init(Context *rsc) { |
| 40 | rsc->mHal.funcs.framebuffer.init(rsc, this); |
| 41 | } |
| 42 | |
| 43 | void FBOCache::deinit(Context *rsc) { |
| 44 | rsc->mHal.funcs.framebuffer.destroy(rsc, this); |
Alex Sakhartchouk | 7d9c5ff | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | void FBOCache::bindColorTarget(Context *rsc, Allocation *a, uint32_t slot) { |
Alex Sakhartchouk | da6d34a | 2011-05-13 14:53:34 -0700 | [diff] [blame] | 48 | if (slot >= mHal.state.colorTargetsCount) { |
Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 49 | ALOGE("Invalid render target index"); |
Alex Sakhartchouk | 7d9c5ff | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 50 | return; |
| 51 | } |
| 52 | if (a != NULL) { |
| 53 | if (!a->getIsTexture()) { |
Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 54 | ALOGE("Invalid Color Target"); |
Alex Sakhartchouk | 7d9c5ff | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 55 | return; |
| 56 | } |
Alex Sakhartchouk | 7d9c5ff | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 57 | } |
Alex Sakhartchouk | 064aa7e | 2011-10-18 10:54:29 -0700 | [diff] [blame] | 58 | mColorTargets[slot].set(a); |
| 59 | mHal.state.colorTargets[slot] = a; |
Alex Sakhartchouk | 7d9c5ff | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 60 | mDirty = true; |
| 61 | } |
| 62 | |
| 63 | void FBOCache::bindDepthTarget(Context *rsc, Allocation *a) { |
| 64 | if (a != NULL) { |
| 65 | if (!a->getIsRenderTarget()) { |
Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 66 | ALOGE("Invalid Depth Target"); |
Alex Sakhartchouk | 7d9c5ff | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 67 | return; |
| 68 | } |
Alex Sakhartchouk | 7d9c5ff | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 69 | } |
Alex Sakhartchouk | 064aa7e | 2011-10-18 10:54:29 -0700 | [diff] [blame] | 70 | mDepthTarget.set(a); |
| 71 | mHal.state.depthTarget = a; |
Alex Sakhartchouk | 7d9c5ff | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 72 | mDirty = true; |
| 73 | } |
| 74 | |
| 75 | void FBOCache::resetAll(Context *) { |
Alex Sakhartchouk | da6d34a | 2011-05-13 14:53:34 -0700 | [diff] [blame] | 76 | for (uint32_t i = 0; i < mHal.state.colorTargetsCount; i ++) { |
Alex Sakhartchouk | 064aa7e | 2011-10-18 10:54:29 -0700 | [diff] [blame] | 77 | mColorTargets[i].set(NULL); |
| 78 | mHal.state.colorTargets[i] = NULL; |
Alex Sakhartchouk | 7d9c5ff | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 79 | } |
Alex Sakhartchouk | 064aa7e | 2011-10-18 10:54:29 -0700 | [diff] [blame] | 80 | mDepthTarget.set(NULL); |
| 81 | mHal.state.depthTarget = NULL; |
Alex Sakhartchouk | 7d9c5ff | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 82 | mDirty = true; |
| 83 | } |
| 84 | |
Alex Sakhartchouk | c19ff01 | 2011-05-06 14:59:45 -0700 | [diff] [blame] | 85 | void FBOCache::setup(Context *rsc) { |
Alex Sakhartchouk | 7d9c5ff | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 86 | if (!mDirty) { |
| 87 | return; |
| 88 | } |
| 89 | |
Alex Sakhartchouk | da6d34a | 2011-05-13 14:53:34 -0700 | [diff] [blame] | 90 | rsc->mHal.funcs.framebuffer.setActive(rsc, this); |
| 91 | |
Alex Sakhartchouk | c19ff01 | 2011-05-06 14:59:45 -0700 | [diff] [blame] | 92 | mDirty = false; |
Alex Sakhartchouk | 7d9c5ff | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 93 | } |