blob: 1da327fef20d90c83d9ba64f218feaca5fdaf3b3 [file] [log] [blame]
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -07001/*
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 Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070022using namespace android;
23using namespace android::renderscript;
24
25
26FBOCache::FBOCache() {
Alex Sakhartchoukc19ff012011-05-06 14:59:45 -070027 mDirty = true;
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070028 mHal.state.colorTargetsCount = 1;
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -070029 mHal.state.colorTargets = new Allocation*[mHal.state.colorTargetsCount];
30 mColorTargets = new ObjectBaseRef<Allocation>[mHal.state.colorTargetsCount];
31 resetAll(NULL);
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070032}
33
34FBOCache::~FBOCache() {
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070035 delete[] mHal.state.colorTargets;
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -070036 delete[] mColorTargets;
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070037}
38
39void FBOCache::init(Context *rsc) {
40 rsc->mHal.funcs.framebuffer.init(rsc, this);
41}
42
43void FBOCache::deinit(Context *rsc) {
44 rsc->mHal.funcs.framebuffer.destroy(rsc, this);
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070045}
46
47void FBOCache::bindColorTarget(Context *rsc, Allocation *a, uint32_t slot) {
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070048 if (slot >= mHal.state.colorTargetsCount) {
Steve Blockaf12ac62012-01-06 19:20:56 +000049 ALOGE("Invalid render target index");
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070050 return;
51 }
52 if (a != NULL) {
Jason Samsb3220332012-04-02 14:41:54 -070053 if (!(a->getIsTexture() || (a->mHal.state.usageFlags & RS_ALLOCATION_USAGE_IO_OUTPUT))) {
Steve Blockaf12ac62012-01-06 19:20:56 +000054 ALOGE("Invalid Color Target");
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070055 return;
56 }
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070057 }
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -070058 mColorTargets[slot].set(a);
59 mHal.state.colorTargets[slot] = a;
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070060 mDirty = true;
61}
62
63void FBOCache::bindDepthTarget(Context *rsc, Allocation *a) {
64 if (a != NULL) {
65 if (!a->getIsRenderTarget()) {
Steve Blockaf12ac62012-01-06 19:20:56 +000066 ALOGE("Invalid Depth Target");
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070067 return;
68 }
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070069 }
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -070070 mDepthTarget.set(a);
71 mHal.state.depthTarget = a;
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070072 mDirty = true;
73}
74
75void FBOCache::resetAll(Context *) {
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070076 for (uint32_t i = 0; i < mHal.state.colorTargetsCount; i ++) {
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -070077 mColorTargets[i].set(NULL);
78 mHal.state.colorTargets[i] = NULL;
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070079 }
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -070080 mDepthTarget.set(NULL);
81 mHal.state.depthTarget = NULL;
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070082 mDirty = true;
83}
84
Alex Sakhartchoukc19ff012011-05-06 14:59:45 -070085void FBOCache::setup(Context *rsc) {
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070086 if (!mDirty) {
87 return;
88 }
89
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070090 rsc->mHal.funcs.framebuffer.setActive(rsc, this);
91
Alex Sakhartchoukc19ff012011-05-06 14:59:45 -070092 mDirty = false;
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070093}