Romain Guy | e2d345e | 2010-09-24 18:39:22 -0700 | [diff] [blame] | 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 | |
Romain Guy | eb99356 | 2010-10-05 18:14:38 -0700 | [diff] [blame] | 17 | #include <stdlib.h> |
| 18 | |
Romain Guy | c9855a5 | 2011-01-21 21:14:15 -0800 | [diff] [blame] | 19 | #include "Debug.h" |
Romain Guy | e2d345e | 2010-09-24 18:39:22 -0700 | [diff] [blame] | 20 | #include "FboCache.h" |
| 21 | #include "Properties.h" |
| 22 | |
| 23 | namespace android { |
| 24 | namespace uirenderer { |
| 25 | |
| 26 | /////////////////////////////////////////////////////////////////////////////// |
| 27 | // Constructors/destructor |
| 28 | /////////////////////////////////////////////////////////////////////////////// |
| 29 | |
Chris Craik | 48a8f43 | 2016-02-05 15:59:29 -0800 | [diff] [blame] | 30 | FboCache::FboCache() |
| 31 | : mMaxSize(Properties::fboCacheSize) {} |
Romain Guy | e2d345e | 2010-09-24 18:39:22 -0700 | [diff] [blame] | 32 | |
| 33 | FboCache::~FboCache() { |
| 34 | clear(); |
| 35 | } |
| 36 | |
| 37 | /////////////////////////////////////////////////////////////////////////////// |
| 38 | // Size management |
| 39 | /////////////////////////////////////////////////////////////////////////////// |
| 40 | |
| 41 | uint32_t FboCache::getSize() { |
| 42 | return mCache.size(); |
| 43 | } |
| 44 | |
| 45 | uint32_t FboCache::getMaxSize() { |
| 46 | return mMaxSize; |
| 47 | } |
| 48 | |
| 49 | /////////////////////////////////////////////////////////////////////////////// |
| 50 | // Caching |
| 51 | /////////////////////////////////////////////////////////////////////////////// |
| 52 | |
| 53 | void FboCache::clear() { |
Romain Guy | eb99356 | 2010-10-05 18:14:38 -0700 | [diff] [blame] | 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(); |
Romain Guy | e2d345e | 2010-09-24 18:39:22 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | GLuint FboCache::get() { |
Romain Guy | eb99356 | 2010-10-05 18:14:38 -0700 | [diff] [blame] | 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; |
Romain Guy | e2d345e | 2010-09-24 18:39:22 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | bool FboCache::put(GLuint fbo) { |
Romain Guy | eb99356 | 2010-10-05 18:14:38 -0700 | [diff] [blame] | 73 | if (mCache.size() < mMaxSize) { |
| 74 | mCache.add(fbo); |
| 75 | return true; |
| 76 | } |
| 77 | |
| 78 | glDeleteFramebuffers(1, &fbo); |
Romain Guy | e2d345e | 2010-09-24 18:39:22 -0700 | [diff] [blame] | 79 | return false; |
| 80 | } |
| 81 | |
| 82 | }; // namespace uirenderer |
| 83 | }; // namespace android |