Alex Sakhartchouk | 8e90f2b | 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 | 8e90f2b | 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 | 407cae9 | 2011-05-06 14:59:45 -0700 | [diff] [blame] | 27 | mDirty = true; |
Alex Sakhartchouk | 2f6964f | 2011-05-13 14:53:34 -0700 | [diff] [blame^] | 28 | mHal.state.colorTargetsCount = 1; |
| 29 | mHal.state.colorTargets = new ObjectBaseRef<Allocation>[mHal.state.colorTargetsCount]; |
Alex Sakhartchouk | 8e90f2b | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | FBOCache::~FBOCache() { |
Alex Sakhartchouk | 2f6964f | 2011-05-13 14:53:34 -0700 | [diff] [blame^] | 33 | delete[] mHal.state.colorTargets; |
| 34 | } |
| 35 | |
| 36 | void FBOCache::init(Context *rsc) { |
| 37 | rsc->mHal.funcs.framebuffer.init(rsc, this); |
| 38 | } |
| 39 | |
| 40 | void FBOCache::deinit(Context *rsc) { |
| 41 | rsc->mHal.funcs.framebuffer.destroy(rsc, this); |
Alex Sakhartchouk | 8e90f2b | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | void FBOCache::bindColorTarget(Context *rsc, Allocation *a, uint32_t slot) { |
Alex Sakhartchouk | 2f6964f | 2011-05-13 14:53:34 -0700 | [diff] [blame^] | 45 | if (slot >= mHal.state.colorTargetsCount) { |
Alex Sakhartchouk | 8e90f2b | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 46 | LOGE("Invalid render target index"); |
| 47 | return; |
| 48 | } |
| 49 | if (a != NULL) { |
| 50 | if (!a->getIsTexture()) { |
| 51 | LOGE("Invalid Color Target"); |
| 52 | return; |
| 53 | } |
| 54 | if (a->getIsTexture()) { |
| 55 | if (a->getTextureID() == 0) { |
| 56 | a->deferredUploadToTexture(rsc); |
| 57 | } |
| 58 | } else if (a->getRenderTargetID() == 0) { |
| 59 | a->deferredAllocateRenderTarget(rsc); |
| 60 | } |
| 61 | } |
Alex Sakhartchouk | 2f6964f | 2011-05-13 14:53:34 -0700 | [diff] [blame^] | 62 | mHal.state.colorTargets[slot].set(a); |
Alex Sakhartchouk | 8e90f2b | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 63 | mDirty = true; |
| 64 | } |
| 65 | |
| 66 | void FBOCache::bindDepthTarget(Context *rsc, Allocation *a) { |
| 67 | if (a != NULL) { |
| 68 | if (!a->getIsRenderTarget()) { |
| 69 | LOGE("Invalid Depth Target"); |
| 70 | return; |
| 71 | } |
| 72 | if (a->getIsTexture()) { |
| 73 | if (a->getTextureID() == 0) { |
| 74 | a->deferredUploadToTexture(rsc); |
| 75 | } |
| 76 | } else if (a->getRenderTargetID() == 0) { |
| 77 | a->deferredAllocateRenderTarget(rsc); |
| 78 | } |
| 79 | } |
Alex Sakhartchouk | 2f6964f | 2011-05-13 14:53:34 -0700 | [diff] [blame^] | 80 | mHal.state.depthTarget.set(a); |
Alex Sakhartchouk | 8e90f2b | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 81 | mDirty = true; |
| 82 | } |
| 83 | |
| 84 | void FBOCache::resetAll(Context *) { |
Alex Sakhartchouk | 2f6964f | 2011-05-13 14:53:34 -0700 | [diff] [blame^] | 85 | for (uint32_t i = 0; i < mHal.state.colorTargetsCount; i ++) { |
| 86 | mHal.state.colorTargets[i].set(NULL); |
Alex Sakhartchouk | 8e90f2b | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 87 | } |
Alex Sakhartchouk | 2f6964f | 2011-05-13 14:53:34 -0700 | [diff] [blame^] | 88 | mHal.state.depthTarget.set(NULL); |
Alex Sakhartchouk | 8e90f2b | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 89 | mDirty = true; |
| 90 | } |
| 91 | |
Alex Sakhartchouk | 407cae9 | 2011-05-06 14:59:45 -0700 | [diff] [blame] | 92 | void FBOCache::setup(Context *rsc) { |
Alex Sakhartchouk | 8e90f2b | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 93 | if (!mDirty) { |
| 94 | return; |
| 95 | } |
| 96 | |
Alex Sakhartchouk | 2f6964f | 2011-05-13 14:53:34 -0700 | [diff] [blame^] | 97 | if (mHal.state.depthTarget.get() != NULL) { |
| 98 | mHal.state.depthTarget->uploadCheck(rsc); |
Alex Sakhartchouk | 8e90f2b | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 99 | } |
Alex Sakhartchouk | 2f6964f | 2011-05-13 14:53:34 -0700 | [diff] [blame^] | 100 | |
| 101 | for (uint32_t i = 0; i < mHal.state.colorTargetsCount; i ++) { |
| 102 | if (mHal.state.colorTargets[i].get() != NULL) { |
| 103 | mHal.state.colorTargets[i]->uploadCheck(rsc); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | rsc->mHal.funcs.framebuffer.setActive(rsc, this); |
| 108 | |
Alex Sakhartchouk | 407cae9 | 2011-05-06 14:59:45 -0700 | [diff] [blame] | 109 | mDirty = false; |
Alex Sakhartchouk | 8e90f2b | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 110 | } |