blob: 31a51b7c22a6904c101e11ae2fc4c6f5b12449e1 [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;
29 mHal.state.colorTargets = new ObjectBaseRef<Allocation>[mHal.state.colorTargetsCount];
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070030}
31
32FBOCache::~FBOCache() {
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070033 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);
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070042}
43
44void FBOCache::bindColorTarget(Context *rsc, Allocation *a, uint32_t slot) {
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070045 if (slot >= mHal.state.colorTargetsCount) {
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070046 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 Sakhartchoukda6d34a2011-05-13 14:53:34 -070062 mHal.state.colorTargets[slot].set(a);
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070063 mDirty = true;
64}
65
66void 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 Sakhartchoukda6d34a2011-05-13 14:53:34 -070080 mHal.state.depthTarget.set(a);
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070081 mDirty = true;
82}
83
84void FBOCache::resetAll(Context *) {
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070085 for (uint32_t i = 0; i < mHal.state.colorTargetsCount; i ++) {
86 mHal.state.colorTargets[i].set(NULL);
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070087 }
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070088 mHal.state.depthTarget.set(NULL);
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070089 mDirty = true;
90}
91
Alex Sakhartchoukc19ff012011-05-06 14:59:45 -070092void FBOCache::setup(Context *rsc) {
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070093 if (!mDirty) {
94 return;
95 }
96
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070097 if (mHal.state.depthTarget.get() != NULL) {
98 mHal.state.depthTarget->uploadCheck(rsc);
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070099 }
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -0700100
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 Sakhartchoukc19ff012011-05-06 14:59:45 -0700109 mDirty = false;
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -0700110}