blob: 871e5115ded1619f946eddd8a929169105e9bc4b [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
Chih-Hung Hsieh11496ac2016-11-15 15:14:05 -080022namespace android {
23namespace renderscript {
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070024
25FBOCache::FBOCache() {
Alex Sakhartchoukc19ff012011-05-06 14:59:45 -070026 mDirty = true;
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070027 mHal.state.colorTargetsCount = 1;
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -070028 mHal.state.colorTargets = new Allocation*[mHal.state.colorTargetsCount];
29 mColorTargets = new ObjectBaseRef<Allocation>[mHal.state.colorTargetsCount];
Chris Wailes44bef6f2014-08-12 13:51:10 -070030 resetAll(nullptr);
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070031}
32
33FBOCache::~FBOCache() {
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070034 delete[] mHal.state.colorTargets;
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -070035 delete[] mColorTargets;
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070036}
37
38void FBOCache::init(Context *rsc) {
39 rsc->mHal.funcs.framebuffer.init(rsc, this);
40}
41
42void FBOCache::deinit(Context *rsc) {
43 rsc->mHal.funcs.framebuffer.destroy(rsc, this);
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070044}
45
46void FBOCache::bindColorTarget(Context *rsc, Allocation *a, uint32_t slot) {
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070047 if (slot >= mHal.state.colorTargetsCount) {
Steve Blockaf12ac62012-01-06 19:20:56 +000048 ALOGE("Invalid render target index");
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070049 return;
50 }
Chris Wailes44bef6f2014-08-12 13:51:10 -070051 if (a != nullptr) {
Jason Samsb3220332012-04-02 14:41:54 -070052 if (!(a->getIsTexture() || (a->mHal.state.usageFlags & RS_ALLOCATION_USAGE_IO_OUTPUT))) {
Steve Blockaf12ac62012-01-06 19:20:56 +000053 ALOGE("Invalid Color Target");
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070054 return;
55 }
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070056 }
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -070057 mColorTargets[slot].set(a);
58 mHal.state.colorTargets[slot] = a;
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070059 mDirty = true;
60}
61
62void FBOCache::bindDepthTarget(Context *rsc, Allocation *a) {
Chris Wailes44bef6f2014-08-12 13:51:10 -070063 if (a != nullptr) {
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070064 if (!a->getIsRenderTarget()) {
Steve Blockaf12ac62012-01-06 19:20:56 +000065 ALOGE("Invalid Depth Target");
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070066 return;
67 }
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070068 }
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -070069 mDepthTarget.set(a);
70 mHal.state.depthTarget = a;
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070071 mDirty = true;
72}
73
74void FBOCache::resetAll(Context *) {
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070075 for (uint32_t i = 0; i < mHal.state.colorTargetsCount; i ++) {
Chris Wailes44bef6f2014-08-12 13:51:10 -070076 mColorTargets[i].set(nullptr);
77 mHal.state.colorTargets[i] = nullptr;
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070078 }
Chris Wailes44bef6f2014-08-12 13:51:10 -070079 mDepthTarget.set(nullptr);
80 mHal.state.depthTarget = nullptr;
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070081 mDirty = true;
82}
83
Alex Sakhartchoukc19ff012011-05-06 14:59:45 -070084void FBOCache::setup(Context *rsc) {
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070085 if (!mDirty) {
86 return;
87 }
88
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070089 rsc->mHal.funcs.framebuffer.setActive(rsc, this);
90
Alex Sakhartchoukc19ff012011-05-06 14:59:45 -070091 mDirty = false;
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070092}
Chih-Hung Hsieh11496ac2016-11-15 15:14:05 -080093
94} // namespace renderscript
95} // namespace android