1 /* 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 #include <stdlib.h> 18 19 #include "Debug.h" 20 #include "FboCache.h" 21 #include "Properties.h" 22 23 namespace android { 24 namespace uirenderer { 25 26 /////////////////////////////////////////////////////////////////////////////// 27 // Constructors/destructor 28 /////////////////////////////////////////////////////////////////////////////// 29 FboCache()30FboCache::FboCache() 31 : mMaxSize(Properties::fboCacheSize) {} 32 ~FboCache()33FboCache::~FboCache() { 34 clear(); 35 } 36 37 /////////////////////////////////////////////////////////////////////////////// 38 // Size management 39 /////////////////////////////////////////////////////////////////////////////// 40 getSize()41uint32_t FboCache::getSize() { 42 return mCache.size(); 43 } 44 getMaxSize()45uint32_t FboCache::getMaxSize() { 46 return mMaxSize; 47 } 48 49 /////////////////////////////////////////////////////////////////////////////// 50 // Caching 51 /////////////////////////////////////////////////////////////////////////////// 52 clear()53void FboCache::clear() { 54 for (size_t i = 0; i < mCache.size(); i++) { 55 const GLuint fbo = mCache.itemAt(i); 56 glDeleteFramebuffers(1, &fbo); 57 } 58 mCache.clear(); 59 } 60 get()61GLuint FboCache::get() { 62 GLuint fbo; 63 if (mCache.size() > 0) { 64 fbo = mCache.itemAt(mCache.size() - 1); 65 mCache.removeAt(mCache.size() - 1); 66 } else { 67 glGenFramebuffers(1, &fbo); 68 } 69 return fbo; 70 } 71 put(GLuint fbo)72bool FboCache::put(GLuint fbo) { 73 if (mCache.size() < mMaxSize) { 74 mCache.add(fbo); 75 return true; 76 } 77 78 glDeleteFramebuffers(1, &fbo); 79 return false; 80 } 81 82 }; // namespace uirenderer 83 }; // namespace android 84