blob: b2181b60054fefbb8bef1792f93d40e0e3b6c7f5 [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
Romain Guyeb993562010-10-05 18:14:38 -070017#include <stdlib.h>
18
Romain Guyc9855a52011-01-21 21:14:15 -080019#include "Debug.h"
Romain Guye2d345e2010-09-24 18:39:22 -070020#include "FboCache.h"
21#include "Properties.h"
22
23namespace android {
24namespace uirenderer {
25
26///////////////////////////////////////////////////////////////////////////////
27// Constructors/destructor
28///////////////////////////////////////////////////////////////////////////////
29
Chris Craik48a8f432016-02-05 15:59:29 -080030FboCache::FboCache()
31 : mMaxSize(Properties::fboCacheSize) {}
Romain Guye2d345e2010-09-24 18:39:22 -070032
33FboCache::~FboCache() {
34 clear();
35}
36
37///////////////////////////////////////////////////////////////////////////////
38// Size management
39///////////////////////////////////////////////////////////////////////////////
40
41uint32_t FboCache::getSize() {
42 return mCache.size();
43}
44
45uint32_t FboCache::getMaxSize() {
46 return mMaxSize;
47}
48
49///////////////////////////////////////////////////////////////////////////////
50// Caching
51///////////////////////////////////////////////////////////////////////////////
52
53void FboCache::clear() {
Romain Guyeb993562010-10-05 18:14:38 -070054 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 Guye2d345e2010-09-24 18:39:22 -070059}
60
61GLuint FboCache::get() {
Romain Guyeb993562010-10-05 18:14:38 -070062 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 Guye2d345e2010-09-24 18:39:22 -070070}
71
72bool FboCache::put(GLuint fbo) {
Romain Guyeb993562010-10-05 18:14:38 -070073 if (mCache.size() < mMaxSize) {
74 mCache.add(fbo);
75 return true;
76 }
77
78 glDeleteFramebuffers(1, &fbo);
Romain Guye2d345e2010-09-24 18:39:22 -070079 return false;
80}
81
82}; // namespace uirenderer
83}; // namespace android