blob: 88302cc52c2bd425476f11a501eda8a7148428c5 [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
John Reck1bcacfd2017-11-03 10:12:19 -070030FboCache::FboCache() : mMaxSize(0) {}
Romain Guye2d345e2010-09-24 18:39:22 -070031
32FboCache::~FboCache() {
33 clear();
34}
35
36///////////////////////////////////////////////////////////////////////////////
37// Size management
38///////////////////////////////////////////////////////////////////////////////
39
40uint32_t FboCache::getSize() {
41 return mCache.size();
42}
43
44uint32_t FboCache::getMaxSize() {
45 return mMaxSize;
46}
47
48///////////////////////////////////////////////////////////////////////////////
49// Caching
50///////////////////////////////////////////////////////////////////////////////
51
52void FboCache::clear() {
Romain Guyeb993562010-10-05 18:14:38 -070053 for (size_t i = 0; i < mCache.size(); i++) {
54 const GLuint fbo = mCache.itemAt(i);
55 glDeleteFramebuffers(1, &fbo);
56 }
57 mCache.clear();
Romain Guye2d345e2010-09-24 18:39:22 -070058}
59
60GLuint FboCache::get() {
Romain Guyeb993562010-10-05 18:14:38 -070061 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;
Romain Guye2d345e2010-09-24 18:39:22 -070069}
70
71bool FboCache::put(GLuint fbo) {
Romain Guyeb993562010-10-05 18:14:38 -070072 if (mCache.size() < mMaxSize) {
73 mCache.add(fbo);
74 return true;
75 }
76
77 glDeleteFramebuffers(1, &fbo);
Romain Guye2d345e2010-09-24 18:39:22 -070078 return false;
79}
80
John Reck1bcacfd2017-11-03 10:12:19 -070081}; // namespace uirenderer
82}; // namespace android