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