The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2006, The Android Open Source Project |
| 4 | ** |
| 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #ifndef ANDROID_OPENGLES_BUFFER_OBJECT_MANAGER_H |
| 19 | #define ANDROID_OPENGLES_BUFFER_OBJECT_MANAGER_H |
| 20 | |
| 21 | #include <stdint.h> |
| 22 | #include <stddef.h> |
| 23 | #include <sys/types.h> |
| 24 | |
| 25 | #include <utils/Atomic.h> |
| 26 | #include <utils/RefBase.h> |
| 27 | #include <utils/KeyedVector.h> |
| 28 | #include <utils/Errors.h> |
| 29 | |
| 30 | #include <GLES/gl.h> |
| 31 | |
| 32 | #include "Tokenizer.h" |
| 33 | #include "TokenManager.h" |
| 34 | |
| 35 | |
| 36 | namespace android { |
| 37 | |
| 38 | // ---------------------------------------------------------------------------- |
| 39 | |
| 40 | namespace gl { |
| 41 | |
| 42 | struct buffer_t { |
| 43 | GLsizeiptr size; |
| 44 | GLenum usage; |
| 45 | uint8_t* data; |
| 46 | uint32_t name; |
| 47 | }; |
| 48 | |
| 49 | }; |
| 50 | |
| 51 | class EGLBufferObjectManager : public TokenManager |
| 52 | { |
| 53 | public: |
| 54 | EGLBufferObjectManager(); |
| 55 | ~EGLBufferObjectManager(); |
| 56 | |
| 57 | // protocol for sp<> |
| 58 | inline void incStrong(const void* id) const; |
| 59 | inline void decStrong(const void* id) const; |
| 60 | typedef void weakref_type; |
| 61 | |
| 62 | gl::buffer_t const* bind(GLuint buffer); |
| 63 | int allocateStore(gl::buffer_t* bo, GLsizeiptr size, GLenum usage); |
| 64 | void deleteBuffers(GLsizei n, const GLuint* buffers); |
| 65 | |
| 66 | private: |
| 67 | mutable volatile int32_t mCount; |
| 68 | mutable Mutex mLock; |
| 69 | KeyedVector<GLuint, gl::buffer_t*> mBuffers; |
| 70 | }; |
| 71 | |
| 72 | void EGLBufferObjectManager::incStrong(const void* id) const { |
| 73 | android_atomic_inc(&mCount); |
| 74 | } |
| 75 | void EGLBufferObjectManager::decStrong(const void* id) const { |
| 76 | if (android_atomic_dec(&mCount) == 1) { |
| 77 | delete this; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | // ---------------------------------------------------------------------------- |
| 82 | }; // namespace android |
| 83 | |
| 84 | #endif // ANDROID_OPENGLES_BUFFER_OBJECT_MANAGER_H |
| 85 | |