blob: 2ef71c24530509f11981014888a33145db39aab5 [file] [log] [blame]
Romain Guye2d345e2010-09-24 18:39:22 -07001/*
2 * Copyright (C) 2010 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#define LOG_TAG "OpenGLRenderer"
18
Romain Guyeb993562010-10-05 18:14:38 -070019#include <stdlib.h>
20
Romain Guye2d345e2010-09-24 18:39:22 -070021#include "FboCache.h"
22#include "Properties.h"
23
24namespace android {
25namespace uirenderer {
26
27///////////////////////////////////////////////////////////////////////////////
28// Constructors/destructor
29///////////////////////////////////////////////////////////////////////////////
30
31FboCache::FboCache(): mMaxSize(DEFAULT_FBO_CACHE_SIZE) {
32 char property[PROPERTY_VALUE_MAX];
33 if (property_get(PROPERTY_FBO_CACHE_SIZE, property, NULL) > 0) {
34 LOGD(" Setting fbo cache size to %s", property);
35 mMaxSize = atoi(property);
36 } else {
37 LOGD(" Using default fbo cache size of %d", DEFAULT_FBO_CACHE_SIZE);
38 }
39}
40
41FboCache::~FboCache() {
42 clear();
43}
44
45///////////////////////////////////////////////////////////////////////////////
46// Size management
47///////////////////////////////////////////////////////////////////////////////
48
49uint32_t FboCache::getSize() {
50 return mCache.size();
51}
52
53uint32_t FboCache::getMaxSize() {
54 return mMaxSize;
55}
56
57///////////////////////////////////////////////////////////////////////////////
58// Caching
59///////////////////////////////////////////////////////////////////////////////
60
61void FboCache::clear() {
Romain Guyeb993562010-10-05 18:14:38 -070062 for (size_t i = 0; i < mCache.size(); i++) {
63 const GLuint fbo = mCache.itemAt(i);
64 glDeleteFramebuffers(1, &fbo);
65 }
66 mCache.clear();
Romain Guye2d345e2010-09-24 18:39:22 -070067}
68
69GLuint FboCache::get() {
Romain Guyeb993562010-10-05 18:14:38 -070070 GLuint fbo;
71 if (mCache.size() > 0) {
72 fbo = mCache.itemAt(mCache.size() - 1);
73 mCache.removeAt(mCache.size() - 1);
74 } else {
75 glGenFramebuffers(1, &fbo);
76 }
77 return fbo;
Romain Guye2d345e2010-09-24 18:39:22 -070078}
79
80bool FboCache::put(GLuint fbo) {
Romain Guyeb993562010-10-05 18:14:38 -070081 if (mCache.size() < mMaxSize) {
82 mCache.add(fbo);
83 return true;
84 }
85
86 glDeleteFramebuffers(1, &fbo);
Romain Guye2d345e2010-09-24 18:39:22 -070087 return false;
88}
89
90}; // namespace uirenderer
91}; // namespace android