blob: beef7bea258db8a3f22e0b4d0917b1254fb49569 [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 Guyc9855a52011-01-21 21:14:15 -080021#include "Debug.h"
Romain Guye2d345e2010-09-24 18:39:22 -070022#include "FboCache.h"
23#include "Properties.h"
24
25namespace android {
26namespace uirenderer {
27
28///////////////////////////////////////////////////////////////////////////////
29// Constructors/destructor
30///////////////////////////////////////////////////////////////////////////////
31
32FboCache::FboCache(): mMaxSize(DEFAULT_FBO_CACHE_SIZE) {
33 char property[PROPERTY_VALUE_MAX];
34 if (property_get(PROPERTY_FBO_CACHE_SIZE, property, NULL) > 0) {
Romain Guyc9855a52011-01-21 21:14:15 -080035 INIT_LOGD(" Setting fbo cache size to %s", property);
Romain Guye2d345e2010-09-24 18:39:22 -070036 mMaxSize = atoi(property);
37 } else {
Romain Guyc9855a52011-01-21 21:14:15 -080038 INIT_LOGD(" Using default fbo cache size of %d", DEFAULT_FBO_CACHE_SIZE);
Romain Guye2d345e2010-09-24 18:39:22 -070039 }
40}
41
42FboCache::~FboCache() {
43 clear();
44}
45
46///////////////////////////////////////////////////////////////////////////////
47// Size management
48///////////////////////////////////////////////////////////////////////////////
49
50uint32_t FboCache::getSize() {
51 return mCache.size();
52}
53
54uint32_t FboCache::getMaxSize() {
55 return mMaxSize;
56}
57
58///////////////////////////////////////////////////////////////////////////////
59// Caching
60///////////////////////////////////////////////////////////////////////////////
61
62void FboCache::clear() {
Romain Guyeb993562010-10-05 18:14:38 -070063 for (size_t i = 0; i < mCache.size(); i++) {
64 const GLuint fbo = mCache.itemAt(i);
65 glDeleteFramebuffers(1, &fbo);
66 }
67 mCache.clear();
Romain Guye2d345e2010-09-24 18:39:22 -070068}
69
70GLuint FboCache::get() {
Romain Guyeb993562010-10-05 18:14:38 -070071 GLuint fbo;
72 if (mCache.size() > 0) {
73 fbo = mCache.itemAt(mCache.size() - 1);
74 mCache.removeAt(mCache.size() - 1);
75 } else {
76 glGenFramebuffers(1, &fbo);
77 }
78 return fbo;
Romain Guye2d345e2010-09-24 18:39:22 -070079}
80
81bool FboCache::put(GLuint fbo) {
Romain Guyeb993562010-10-05 18:14:38 -070082 if (mCache.size() < mMaxSize) {
83 mCache.add(fbo);
84 return true;
85 }
86
87 glDeleteFramebuffers(1, &fbo);
Romain Guye2d345e2010-09-24 18:39:22 -070088 return false;
89}
90
91}; // namespace uirenderer
92}; // namespace android