BufferObjectManager.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #ifndef ANDROID_OPENGLES_BUFFER_OBJECT_MANAGER_H
  18. #define ANDROID_OPENGLES_BUFFER_OBJECT_MANAGER_H
  19. #include <stdint.h>
  20. #include <stddef.h>
  21. #include <sys/types.h>
  22. #include <utils/Atomic.h>
  23. #include <utils/RefBase.h>
  24. #include <utils/KeyedVector.h>
  25. #include <utils/Errors.h>
  26. #include <GLES/gl.h>
  27. #include "Tokenizer.h"
  28. #include "TokenManager.h"
  29. namespace android {
  30. // ----------------------------------------------------------------------------
  31. namespace gl {
  32. struct buffer_t {
  33. GLsizeiptr size;
  34. GLenum usage;
  35. uint8_t* data;
  36. uint32_t name;
  37. };
  38. };
  39. class EGLBufferObjectManager : public TokenManager
  40. {
  41. public:
  42. EGLBufferObjectManager();
  43. ~EGLBufferObjectManager();
  44. // protocol for sp<>
  45. inline void incStrong(const void* id) const;
  46. inline void decStrong(const void* id) const;
  47. typedef void weakref_type;
  48. gl::buffer_t const* bind(GLuint buffer);
  49. int allocateStore(gl::buffer_t* bo, GLsizeiptr size, GLenum usage);
  50. void deleteBuffers(GLsizei n, const GLuint* buffers);
  51. private:
  52. mutable volatile int32_t mCount;
  53. mutable Mutex mLock;
  54. KeyedVector<GLuint, gl::buffer_t*> mBuffers;
  55. };
  56. void EGLBufferObjectManager::incStrong(const void* /*id*/) const {
  57. android_atomic_inc(&mCount);
  58. }
  59. void EGLBufferObjectManager::decStrong(const void* /*id*/) const {
  60. if (android_atomic_dec(&mCount) == 1) {
  61. delete this;
  62. }
  63. }
  64. // ----------------------------------------------------------------------------
  65. }; // namespace android
  66. #endif // ANDROID_OPENGLES_BUFFER_OBJECT_MANAGER_H