| The Android Open Source Project | edbf3b6 | 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 |  | 
| Jesse Hall | 3aa75f9 | 2016-05-20 10:47:07 -0700 | [diff] [blame] | 21 | #include <atomic> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | #include <stdint.h> | 
|  | 23 | #include <stddef.h> | 
|  | 24 | #include <sys/types.h> | 
|  | 25 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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: | 
| Jesse Hall | 3aa75f9 | 2016-05-20 10:47:07 -0700 | [diff] [blame] | 67 | mutable std::atomic_size_t          mCount; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | mutable Mutex                       mLock; | 
|  | 69 | KeyedVector<GLuint, gl::buffer_t*>  mBuffers; | 
|  | 70 | }; | 
|  | 71 |  | 
| Mark Salyzyn | 92dc3fc | 2014-03-12 13:12:44 -0700 | [diff] [blame] | 72 | void EGLBufferObjectManager::incStrong(const void* /*id*/) const { | 
| Jesse Hall | 3aa75f9 | 2016-05-20 10:47:07 -0700 | [diff] [blame] | 73 | mCount.fetch_add(1, std::memory_order_relaxed); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | } | 
| Mark Salyzyn | 92dc3fc | 2014-03-12 13:12:44 -0700 | [diff] [blame] | 75 | void EGLBufferObjectManager::decStrong(const void* /*id*/) const { | 
| Jesse Hall | 3aa75f9 | 2016-05-20 10:47:07 -0700 | [diff] [blame] | 76 | if (mCount.fetch_sub(1, std::memory_order_release) == 0) { | 
|  | 77 | std::atomic_thread_fence(std::memory_order_acquire); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | delete this; | 
|  | 79 | } | 
|  | 80 | } | 
|  | 81 |  | 
|  | 82 | // ---------------------------------------------------------------------------- | 
|  | 83 | }; // namespace android | 
|  | 84 |  | 
|  | 85 | #endif // ANDROID_OPENGLES_BUFFER_OBJECT_MANAGER_H | 
|  | 86 |  |