rsFBOCache.cpp revision a94952436aeb251f587c1bccdf94c7f75285dfe2
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
22using namespace android;
23using namespace android::renderscript;
24
25
26FBOCache::FBOCache() {
27    mDirty = true;
28    mHal.state.colorTargetsCount = 1;
29    mHal.state.colorTargets = new ObjectBaseRef<Allocation>[mHal.state.colorTargetsCount];
30}
31
32FBOCache::~FBOCache() {
33    delete[] mHal.state.colorTargets;
34}
35
36void FBOCache::init(Context *rsc) {
37    rsc->mHal.funcs.framebuffer.init(rsc, this);
38}
39
40void FBOCache::deinit(Context *rsc) {
41    rsc->mHal.funcs.framebuffer.destroy(rsc, this);
42}
43
44void FBOCache::bindColorTarget(Context *rsc, Allocation *a, uint32_t slot) {
45    if (slot >= mHal.state.colorTargetsCount) {
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    }
55    mHal.state.colorTargets[slot].set(a);
56    mDirty = true;
57}
58
59void FBOCache::bindDepthTarget(Context *rsc, Allocation *a) {
60    if (a != NULL) {
61        if (!a->getIsRenderTarget()) {
62            LOGE("Invalid Depth Target");
63            return;
64        }
65    }
66    mHal.state.depthTarget.set(a);
67    mDirty = true;
68}
69
70void FBOCache::resetAll(Context *) {
71    for (uint32_t i = 0; i < mHal.state.colorTargetsCount; i ++) {
72        mHal.state.colorTargets[i].set(NULL);
73    }
74    mHal.state.depthTarget.set(NULL);
75    mDirty = true;
76}
77
78void FBOCache::setup(Context *rsc) {
79    if (!mDirty) {
80        return;
81    }
82
83    rsc->mHal.funcs.framebuffer.setActive(rsc, this);
84
85    mDirty = false;
86}
87