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