2 ** Copyright 2008, The Android Open Source Project
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
8 ** http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <sys/types.h>
21 #include <utils/Atomic.h>
22 #include <utils/RefBase.h>
23 #include <utils/KeyedVector.h>
24 #include <utils/Errors.h>
28 #include "BufferObjectManager.h"
35 // ----------------------------------------------------------------------------
37 EGLBufferObjectManager::EGLBufferObjectManager()
38 : TokenManager(), mCount(0)
42 EGLBufferObjectManager::~EGLBufferObjectManager()
44 // destroy all the buffer objects and their storage
45 GLsizei n = mBuffers.size();
46 for (GLsizei i=0 ; i<n ; i++) {
47 buffer_t* bo = mBuffers.valueAt(i);
53 buffer_t const* EGLBufferObjectManager::bind(GLuint buffer)
55 Mutex::Autolock _l(mLock);
56 int32_t i = mBuffers.indexOfKey(buffer);
58 return mBuffers.valueAt(i);
60 buffer_t* bo = new buffer_t;
62 bo->usage = GL_STATIC_DRAW;
65 mBuffers.add(buffer, bo);
69 int EGLBufferObjectManager::allocateStore(buffer_t* bo,
70 GLsizeiptr size, GLenum usage)
72 Mutex::Autolock _l(mLock);
73 if (size != bo->size) {
74 uint8_t* data = (uint8_t*)malloc(size);
85 void EGLBufferObjectManager::deleteBuffers(GLsizei n, const GLuint* buffers)
87 Mutex::Autolock _l(mLock);
89 const GLuint t = *buffers++;
91 int32_t index = mBuffers.indexOfKey(t);
93 buffer_t* bo = mBuffers.valueAt(index);
95 mBuffers.removeItemsAt(index);
102 // ----------------------------------------------------------------------------
103 }; // namespace android