2 * Copyright (C) 2010 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #define LOG_TAG "OpenGLRenderer"
23 #include "Properties.h"
26 namespace uirenderer {
28 ///////////////////////////////////////////////////////////////////////////////
29 // Constructors/destructor
30 ///////////////////////////////////////////////////////////////////////////////
32 FboCache::FboCache(): mMaxSize(DEFAULT_FBO_CACHE_SIZE) {
33 char property[PROPERTY_VALUE_MAX];
34 if (property_get(PROPERTY_FBO_CACHE_SIZE, property, nullptr) > 0) {
35 INIT_LOGD(" Setting fbo cache size to %s", property);
36 mMaxSize = atoi(property);
38 INIT_LOGD(" Using default fbo cache size of %d", DEFAULT_FBO_CACHE_SIZE);
42 FboCache::~FboCache() {
46 ///////////////////////////////////////////////////////////////////////////////
48 ///////////////////////////////////////////////////////////////////////////////
50 uint32_t FboCache::getSize() {
54 uint32_t FboCache::getMaxSize() {
58 ///////////////////////////////////////////////////////////////////////////////
60 ///////////////////////////////////////////////////////////////////////////////
62 void FboCache::clear() {
63 for (size_t i = 0; i < mCache.size(); i++) {
64 const GLuint fbo = mCache.itemAt(i);
65 glDeleteFramebuffers(1, &fbo);
70 GLuint FboCache::get() {
72 if (mCache.size() > 0) {
73 fbo = mCache.itemAt(mCache.size() - 1);
74 mCache.removeAt(mCache.size() - 1);
76 glGenFramebuffers(1, &fbo);
81 bool FboCache::put(GLuint fbo) {
82 if (mCache.size() < mMaxSize) {
87 glDeleteFramebuffers(1, &fbo);
91 }; // namespace uirenderer
92 }; // namespace android